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

John Meacham john at repetae.net
Sun Apr 22 00:48:45 CEST 2012


Yes, this has always bothered me too.

   John

On Sat, Apr 21, 2012 at 2:51 AM, Andreas Abel <andreas.abel at ifi.lmu.de> wrote:
> 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
>    monadicComputationWhoseResultIWantToDiscard
>    return ()
>
> Cheers,
> Andreas
>
> 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")
>
> vs.
>
>  (\ _ -> 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
> http://www2.tcs.ifi.lmu.de/~abel/
>
> _______________________________________________
> Haskell mailing list
> Haskell at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell



More information about the Haskell mailing list