Generalise type of forever
Stefan O'Rear
stefanor at cox.net
Mon Jan 7 01:39:37 EST 2008
On Sun, Jan 06, 2008 at 10:33:27PM -0800, Don Stewart wrote:
> It's been pointed out by a couple of people that the type of forever
> is overly constrained. We get a few more useful programs for free
> if we change the type:
>
> [generalise type of 'forever' from returning m () to m a
> Don Stewart <dons at galois.com>**20080107062656] {
> hunk ./Control/Monad.hs 42
> - , forever -- :: (Monad m) => m a -> m ()
> + , forever -- :: (Monad m) => m a -> m a
> hunk ./Control/Monad.hs 190
> -forever :: (Monad m) => m a -> m ()
> +forever :: (Monad m) => m a -> m a
> }
>
> In particular, fail breaks out nicely.
>
> > forever Nothing
> Nothing
>
> Deadline: 12th January.
>
> -- Don
Your new type is not more general, for it no longer satisfies e.g.
"Maybe Int -> Maybe ()".
I counter-propose using the principal type, m a -> m b.
Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/libraries/attachments/20080106/fee50603/attachment.bin
More information about the Libraries
mailing list