[Haskell] Types of when and unless in Control.Monad

Andreas Abel andreas.abel at ifi.lmu.de
Sat Apr 21 11:51:40 CEST 2012

In Control.Monad, when has type

   when :: Monad m => Bool -> m () -> m ()

I think this type should be generalized to

   when :: Monad m => Bool -> m a -> m ()

to avoid silly "return ()" statements like in

   when cond $ do
     return ()


P.S.:  A more systematic solution would be to change the Haskell 
language by either introducing a Top type which is the supertype of 
everything and use it instead of ().

Alternatively, make () the top type and interpret matching against the 
empty tuple as just computing the weak head normal form and then 
discarding the result.  The latter is needed to preserve the current 
behavior of

   (\ () -> bla) (error "raised")


   (\ _ -> bla) (error "not raised")

Andreas Abel  <><      Du bist der geliebte Mensch.

Theoretical Computer Science, University of Munich
Oettingenstr. 67, D-80538 Munich, GERMANY

andreas.abel at ifi.lmu.de

More information about the Haskell mailing list