Generalize with MonadAff

55 views
Skip to first unread message

Joop Ringelberg

unread,
Feb 21, 2018, 9:38:54 AM2/21/18
to purescript
I have a question about generalizing. Starting with this function:
  test0 :: String -> String
  test0 s = s

we can generalize it in its argument:
  test1 :: forall a. Show a => a -> String
  test1 s = show s

or in its functional result:
  test12 :: forall a. Show a => String -> a
  test12 s = s

Now consider the following function:
  test2 :: forall e. Aff e Int
  test2 s = pure 0

I would like to generalize it in its functional result:
  test3 :: forall e m. MonadAff e m => m e Int
  test3 s = pure 0

However, I now get an error:
Could not match kind type with kind # Control.Monad.Eff.Effect while checking the kind of MonadAff e m => m e Int in value declaration test3.

I cannot understand why. Moreover, I've found an example of similar such generalizing in Hyper.Node.Server, for example in this type:
    write :: forall m e. MonadAff e m => Buffer -> NodeResponse m e

Alex Berg

unread,
Feb 26, 2018, 1:02:40 AM2/26/18
to purescript
Sorry, don't have an environment with PS compiler available, but did try this? The `e` is part of MonadAff and describes the single `m`, so don't need to include `e` there in `m e Int`.

test3: forall e m. MonadAff e m => m Int
test3 s = pure 0

Joop Ringelberg

unread,
Feb 26, 2018, 2:37:34 AM2/26/18
to purescript
You are quite right! However, I still find an issue with the expressions. Only if I change the type so it actually includes a functional argument, the compiler accepts it:
  test3 :: forall e m. MonadAff e m => Int -> m Int
  test3 = pure
Thank you very much for clarifying this point.
Joop
Reply all
Reply to author
Forward
0 new messages