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.lambda comes from the jewish lambda calculus.
This is SBCL 1.0.48, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>;.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (type-of 2)
(INTEGER 0 536870911)
reducefold, foldl, foldr, foldl', foldr1, foldl1, foldl1'
Haskell | Lisp
---------------------------------|---------------------------------
zip l1 l2 | map list l1 l2
zip3 l1 l2 l3 | map list l1 l2 l3
zip4 l1 l2 l3 l4 | map list l1 l2 l3 l4
zip5 l1 l2 l3 l4 l5 | map list l1 l2 l3 l4 l5
zip6 l1 l2 l3 l4 l5 l6 | map list l1 l2 l3 l4 l5 l6
zip7 l1 l2 l3 l4 l5 l6 l7 | map list l1 l2 l3 l4 l5 l6 l7
N/A | map list . ls
map f l | map f l
zipWith f l1 l2 | map f l1 l2
zipWith3 f l1 l2 l3 | map f l1 l2 l3
zipWith4 f l1 l2 l3 l4 | map f l1 l2 l3 l4
zipWith5 f l1 l2 l3 l4 l5 | map f l1 l2 l3 l4 l5
zipWith6 f l1 l2 l3 l4 l5 l6 | map f l1 l2 l3 l4 l5 l6
zipWith7 f l1 l2 l3 l4 l5 l6 l7 | map f l1 l2 l3 l4 l5 l7
N/A | map f . ls
(defmacro show (&rest xs) ...)
instance (Show a, Show b) => Show (a,b) where
showsPrec _ (a,b) s = show_tuple [shows a, shows b] s
instance (Show a, Show b, Show c) => Show (a, b, c) where
showsPrec _ (a,b,c) s = show_tuple [shows a, shows b, shows c] s
instance (Show a, Show b, Show c, Show d) => Show (a, b, c, d) where
showsPrec _ (a,b,c,d) s = show_tuple [shows a, shows b, shows c, shows d] s
instance (Show a, Show b, Show c, Show d, Show e) => Show (a, b, c, d, e) where
showsPrec _ (a,b,c,d,e) s = show_tuple [shows a, shows b, shows c, shows d, shows e] s
instance (Show a, Show b, Show c, Show d, Show e, Show f) => Show (a,b,c,d,e,f) where
showsPrec _ (a,b,c,d,e,f) s = show_tuple [shows a, shows b, shows c, shows d, shows e, shows f] s
instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g)
=> Show (a,b,c,d,e,f,g) where
showsPrec _ (a,b,c,d,e,f,g) s
= show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g] s
instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h)
=> Show (a,b,c,d,e,f,g,h) where
showsPrec _ (a,b,c,d,e,f,g,h) s
= show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h] s
instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i)
=> Show (a,b,c,d,e,f,g,h,i) where
showsPrec _ (a,b,c,d,e,f,g,h,i) s
= show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
shows i] s
instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j)
=> Show (a,b,c,d,e,f,g,h,i,j) where
showsPrec _ (a,b,c,d,e,f,g,h,i,j) s
= show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
shows i, shows j] s
instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k)
=> Show (a,b,c,d,e,f,g,h,i,j,k) where
showsPrec _ (a,b,c,d,e,f,g,h,i,j,k) s
= show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
shows i, shows j, shows k] s
instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k,
Show l)
=> Show (a,b,c,d,e,f,g,h,i,j,k,l) where
showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l) s
= show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
shows i, shows j, shows k, shows l] s
instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k,
Show l, Show m)
=> Show (a,b,c,d,e,f,g,h,i,j,k,l,m) where
showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m) s
= show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
shows i, shows j, shows k, shows l, shows m] s
instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k,
Show l, Show m, Show n)
=> Show (a,b,c,d,e,f,g,h,i,j,k,l,m,n) where
showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m,n) s
= show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
shows i, shows j, shows k, shows l, shows m, shows n] s
instance (Show a, Show b, Show c, Show d, Show e, Show f, Show g, Show h, Show i, Show j, Show k,
Show l, Show m, Show n, Show o)
=> Show (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) where
showsPrec _ (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) s
= show_tuple [shows a, shows b, shows c, shows d, shows e, shows f, shows g, shows h,
shows i, shows j, shows k, shows l, shows m, shows n, shows o] s
Lisp | Haskell
-------------------------|-------------------------
* (expt -1 (exp 1)) | Prelude> (-1) ** exp 1
#C(-0.6332554 0.7739428) | NaN
Lisp | Haskell
----------------------------|---------------------------------------------------
* (floor (/ 1 0)) | Prelude> floor (1/0)
DIVISION-BY-ZERO signalled | 1797693134862315907729305190789024733617976978942306572
| 7343008115773267580550096313270847732240753602112011387
| 9871393357658789768814416622492847430639474124377767893
| 4248654852763022196012460941194530829520850057688381506
| 8234246288147391311054082723716335051068458629823994724
| 5938479716304835356329624224137216
(defvar xs '(1))
(rplacd xs xs)
xs
(mapcar #'print xs)(keep f xs) is much more consistent than {x∈xs|f(x)} craziness.