Pm_tut> :t negate negate :: Num a => a -> a ##```## Pm_tut> :t (-) (-) :: Num a => a -> a -> a ##``````## nats = [0..] ##``````## Pm_tut> take 10 nats [0,1,2,3,4,5,6,7,8,9] ##``````## open FH, '<', \$file or die "Can't open \$file for reading: \$!\n"; ##``````## const x y = x ##``````## (-) :: Num a => a -> a -> a ##``````## (-) :: Num a => (a, a) -> a ##``````## (-) :: Num a => a -> (a -> a) ##``````## (5-) ##``````## Pm_tut> putStr "Hello, world!\n" Hello, world! Pm_tut> ##``````## factorial n = if n == 0 then 1 else n * factorial (n-1) ##``````## Pm_tut> :t factorial factorial :: Num a => a -> a ##``````## factorial 0 = 1 factorial n = n * factorial (n-1) ##``````## factorial n = n * factorial (n-1) factorial 0 = 1 ##``````## factorial 0 = 1 factorial (n+1) = (n+1) * factorial n ##``````## factorial n = tr n 1 where tr 0 f = f tr n f = tr (n-1) (n*f) ##``````## factorial n = product [1..n] ##``````## product = foldl (*) 1 ##``````## foldl f z [] = z foldl f z (x:xs) = foldl f (f z x) xs ##``````## product xs = foldl (*) 1 xs ##``````## sum xs = foldl (+) 0 xs -- this is in the Standard Prelude, too ##``````## or xs = foldl (||) False xs -- this is also in the Prelude ##``````## and xs = foldl (&&) True xs -- so is this ##``````## anyprime xs = or (map prime xs) -- map does what you'd expect allprime xs = and (map prime xs) ##``````## foldl :: (a -> b -> a) -> a -> [b] -> a ##``````## andprime p n = p && prime n allprime xs = foldl andprime True xs ##``````## allprime xs = foldl (\p n -> p && prime n) True xs ##``````## factorials = scanl (*) 1 [1..] ##``````## Pm_tut> take 10 factorials [1,1,2,6,24,120,720,5040,40320,362880] Pm_tut> factorials !! 24 620448401733239439360000 ##``````## Pm_tut> factorials !! 65536 ERROR - Garbage collection fails to reclaim sufficient space Pm_tut> ```