3 ms·
I'm been experimenting with UHC's js backend. One of the things that struck me was that in Haskell if I have a function like: forever :: Monad m => m a ->
by DanWaterworth 15y ago
I'm been experimenting with UHC's js backend. One of the things that struck me was that in Haskell if I have a function like:
forever :: Monad m => m a -> m a
I can use it for either asynchronous or synchronous javascript, e.g
forever :: IO a -> IO a
forever :: ContT r IO a -> ContT r IO a
The same function can take a synchronous js function or an async js function and run it in an infinite loop. For this reason, I think that if you want to learn from Haskell in writing reusable js then you should look into monads.
- Martijn 15y agoSmall nitpick, the type of forever is actually: forever :: Monad m => m a -> m b Since it never returns a value, the resulting monadic action can be polymorphic in its return type.