[Haskell-cafe] more thoughts on "Finally tagless"

Tom Schrijvers tom.schrijvers at cs.kuleuven.be
Mon Mar 8 15:14:54 EST 2010


> Yeah, subject "Finally Tagless" again, sorry, I'm just not done with it yet.
>
> In Olegs haskell implementation he is using classes mainly to model the
> syntax and instances to use for evaluators / compilers to allow multiple
> interpretations.
>
> I wonder if it'd be possible to do the same without classes using data types
> instead?
>
> Something similar to what Luke Palmer has done here:
>
> http://lukepalmer.wordpress.com/2010/01/24/haskell-antipattern-existential-typeclass/

Günther,

You can just use the dictionary translation of type classes to replace
them with data types:

E.g.

class Eval sem where
  val :: Int -> sem Int
  add :: sem Int -> sem Int -> sem Int

>-->

data EvalDict sem = EvalDict { val :: Int -> sem Int, add :: sem Int
-> sem Int -> sem Int }

Cheers,

Tom


More information about the Haskell-Cafe mailing list