[Haskell] do notation and type synonym

Bulat Ziganshin bulatz at HotPOP.com
Mon Aug 8 05:30:12 EDT 2005


Hello mt,

Sunday, August 07, 2005, 10:26:07 PM, you wrote:

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

i think the actual translation is:

m >>= (\var -> case var of
                 5 -> return 0
                 _ -> fail)

where fail = Nothing for Maybe monad

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

constructor gives you type-safety! without constructor there is no
difference between Point and (Float, Float), only constructor give you
syntax difference between these two types!

newtype Point = Point (Float, Float)
unPoint (Point p) = p


-- 
Best regards,
 Bulat                            mailto:bulatz at HotPOP.com





More information about the Haskell mailing list