Advertisement
Madotsuki

Haskell Functions

Sep 3rd, 2014
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Defining a function
  2.  
  3. -- Name input1 input2 input3 input[..] = output
  4. addFive x = x+5
  5.  
  6. -- So those work like arguments...
  7. addFiveInputs x y z a b = x+y+z+a+b
  8.  
  9. -- We can give out multiple outputs and stuff like that
  10. nextFiveItems x = [x+1,x+2,x+3,x+4,x+5]
  11.  
  12. -- Also, we can use let in situations too to help define functions
  13. let superFunction x = x*x in superFunction 30
  14.  
  15. -- So here's an example demonstrating some of this...
  16. twoOutputFunction x y = (x+4,y-3)
  17. let (p,r) = twoOutputFunction 30 50 in (p,r) -- or something less stupid, lol
  18.  
  19. -- All of these functions need to be loaded as a module like an .hs file to test them out.
  20. -- And the let items need to be commented out too.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement