
12 May
2009
12 May
'09
8:50 a.m.
Am Dienstag 12 Mai 2009 07:59:01 schrieb michael rice:
In the code below, is the type returned by the return functions inferred from the result type in the function type signature, i.e., just change the result type to Maybe Int and the code will return a Maybe monad, (Just 4), instead of a List monad?
You can find out such things yourself, just remove the type signature and ask ghci/hugs what they think: *MType> :t fn fn :: (MonadPlus m) => [a] -> m a
Michael
=========
import Monad
fn :: [Int] -> [Int] fn l = mzero `mplus` (return (head l)) `mplus` (return (last l))
================
*Main> :l test5 [1 of 1] Compiling Main ( test5.hs, interpreted ) Ok, modules loaded: Main. *Main> fn [4,5,6,7,8] [4,8] *Main>