User talk:Elias
From HaskellWiki
1 Exercises for the enthusiast beginner
1.1 A simple exercise, read carefully
This is a definition for thereadln
(>>=)
p >> q
q(p)
> readln = h > where h = getChar >>= f > where f c = case c of > '\n' -> return [] > otherwise -> h >>= (return . (:) c)
try
Main> readln >>= print
It works, as expected.
Nowhofun
readln
readln'
hofun
> readln' = hofun getChar '\n' (:) [] > hofun r s op e = h > where h = r >>= f > where f c = case c of > s -> return e > otherwise -> h >>= (return . op c)
try
Main> readln' >>= print
readln' >>= print
readln >>= print
