[Haskell] do notation and type synonym

mt mtvo at info.fundp.ac.be
Sun Aug 7 14:26:07 EDT 2005


hi,

first one :
i've read in different places that "there is nothing magic with do"
and that

	do { x <- m ; return x }

is the *same* as

	m >>= \x -> return x

however i've came up with :

m :: Maybe Int
m = return 4

check5  = do { 5 <- m ; return 0 }
check5' = m >>= \5 -> return 0

the first check5 is ok and return Nothing while the second check5' will raise 
an "Exception: Non-exhaustive patterns" (which is what i've expected).

the sentence "there is nothing magic with do" with its reason are important 
for me to understand monads and do notation, so maybe someone can rephrase 
"there is nothing magic with do" and explain the exposed behavior?


second one:
is it possible to write something like
type Point = (Float, Float)
type Vector = (Float, Float)
and still have type safety (i.e. not be able to mix Point and Vector) (and 
still have (*,*) without constructor)?

thanks,
minh thu


More information about the Haskell mailing list