[Haskell-cafe] Extensible Effects & Multiple Operations

Tobias Florek haskell at ibotty.net
Thu Jul 17 22:32:11 UTC 2014


hi,

 > My problem is I cannot figure out how to define one "runner" for my
> Effect that can deal with operations with different result types.

afaict you have two possibilities.

  * `OpenFile` is essentially a `Reader Handle` and
`readFrom :: (SetMember Lift IO r, Member OpenFile r) => Eff r Char` 
asks for the handle and works with that (in `IO`).

  * if you don't want to impose `SetMember Lift IO`, you will have to 
live with a sum type in your `OpenFile`, but not with `Result`. just use

     data OpenFile v = Read (Char -> v)
                     | EOF  (Bool -> v)
       deriving Typeable



btw: i find working with `ScopedTypeVariables` easier than using your 
`asTypeOf`. but even then, you should maybe define your own

     prj' :: Union (OpenFile :> r) (VE (OpenFile :> r) result) -> Maybe 
(OpenFile (VE (OpenFile :> r) result))
     prj' = prj

iff you really need it, which you don't in this example.


have fun with extensible effects,
  tob


More information about the Haskell-Cafe mailing list