[Haskell] do notation and type synonym
Lemmih
lemmih at gmail.com
Sun Aug 7 14:40:18 EDT 2005
On 8/7/05, mt <mtvo at info.fundp.ac.be> wrote:
> 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?
Read http://www.haskell.org/onlinereport/exps.html, section 3.14.
> 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)?
No, that's not possible.
--
Friendly,
Lemmih
More information about the Haskell
mailing list