Haskell `forever` type signature -


in haskell why type-signature of forever

forever :: monad m => m -> m b 

specifically why isn't :: monad m => m -> m a? surely type of monad acting upon doesn't change half way through forever?

a function such as:

 forever' :: monad m => m -> m  forever' = forever 

seems work same.

the type signature of forever crafted suggest result runs forever. specifically, there no way write action of type m b (polymorphic in return value) terminates , yields non-bottom value. alternative way suggest same thing forever' :: m -> m void.

another answer general type available function it's defined, that's 1 given.

prelude> let forever m = let x = m >> x in x prelude> :t forever forever :: monad m => m -> m b 

these days, should defined differently:

forever :: applicative f => f -> f b forever = let x = *> x in x 

Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -