Name: Anonymous 2011-05-23 0:34
can someone explain them to me.. I'm thinken they might be simple but my pee sized brain can't comprehend most definitions off of google
add:
add :: Int -> Int -> Int
add x y = x + yz = (add 1), then z is now the following function:
z :: Int -> Int
z y = 1 + yz is a closure of add. This also means that the syntax (add 1) 2 is equivalent to add 1 2.
$ ghci
GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help
Loading package base ... linking ... done.
Prelude> let fac 1 = 1; fac n = n * (fac n-1)
Prelude> (fac 4)
*** Exception: stack overflow
Prelude>
GHCi, version 7.0.1.20101209: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> let fac 1 = 1; fac n = n * (fac [u][o](n - 1)[/o][/u])
Prelude> (fac 4)
24
Prelude>
GHCi, version 7.0.1.20101209: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> let fac 1 = 1; fac n = n * (fac [o][u](n - 1)[/u][/o])
Prelude> (fac 4)
24
Prelude>
fac 1 -> 1; fac N -> N * (fac N-1) works nicely, but haskell's syntax is horrible illogical mess at best.
(+) operators, and you can S-express yourself to your heart's content.
No shit, sherlock. It's a multiparadigm language. And functional programming alone is not a silver bullet. Don't perceive it as such.
$ sbcl
This is SBCL 1.0.11.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>;.
* +3
3
*
$ ghci
GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help
Loading package base ... linking ... done.
Prelude> +3
<interactive>:1:0: parse error on input `+'
Prelude>
(define (f x y z) (+ x (- y z))
(define f-curried ((curry f) 2))
(define f-partially-applied (papply f 2))
(f-curried 3 4) ; should be an error
((f-curried 3) 4) ; ok
(f-partially-applied 3 4) ; ok
((f-partially-applied 3) 4) ; should be an error
(curry f) ≡ (lambda (x) (lambda (y) (lambda (z) (f x y z))))
(papply f . a) ≡ (lambda b (apply f (append a b)))(defun f (x y z) (+ x (- y z)))
(setf (symbol-function 'f-curried) (funcall (curry f) 2))
(setf (symbol-function 'f-partially-applied) (papply f 2))
(f-curried 3 4) ; error
(funcall (f-curried 3) 4) ; ok
(f-partially-applied 3 4) ; ok
(funcall (f-partially-applied 3) 4) ; errorYou neglect to mention that Haskell will never leave academic circles.