|
|
Absolutely. I've been using GHCi (the Glasgow Haskell Compiler's REPL) quite often. Although I think the best way to learn how to design substantial programs is by typing them in a text editor (where you can write more than one line easily), a REPL provides some major advantages:
Makes testing one-liners easy, so you can learn language features quickly:
> (\xs -> zip xs (tail xs)) [1..10]
[(1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(7,8),(8,9),(9,10)]
> (zip <*> tail) [1..10]
[(1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(7,8),(8,9),(9,10)]
>
> sortBy (\a b -> compare (length a) (length b)) ["ab", "abc", "a"]
["a","ab","abc"]
> sortBy (compare `on` length) ["ab", "abc", "a"]
["a","ab","abc"]
Provides in-console documentation:
> :i <*>
class (Functor f) => Applicative f where
...
(<*>) :: f (a -> b) -> f a -> f b
...
-- Defined in Control.Applicative
infixl 4 <*>
>
> :i on
on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
-- Defined in Data.Function
infixl 0 on
Great for doing simple (and even not-so-simple) tasks when you'd rather not write a whole program:
> -- Find longest words that don't have repeated characters.
>
> readFile "/home/joey/twl06" >>= mapM_ putStrLn . take 10 . reverse . sortBy (compare `on` length) . filter ((==) <*> nub) . lines
UNCOPYRIGHTABLE
DERMATOGLYPHICS
TROUBLEMAKINGS
DERMATOGLYPHIC
AMBIDEXTROUSLY
UNPROBLEMATIC
UNPREDICTABLY
TROUBLEMAKING
SUBORDINATELY
MULTIBRANCHED
|
|
|
answered Dec 8 '10 at 17:30
|
|