21 Mar 11:32 2013

## Excercise on tagless final interpreters

matteo vezzola <id074519 <at> studenti.univr.it>

2013-03-21 10:32:21 GMT

2013-03-21 10:32:21 GMT

I'm playing with tagless final interpreters reading [1], using a very simple language: >>> class Ints repr where >>> int :: Integer -> repr Integer >>> (.+.) :: repr Integer -> repr Integer -> repr Integer >>> (.*.) :: repr Integer -> repr Integer -> repr Integer >>> (.-.) :: repr Integer -> repr Integer >>> (.<=.) :: repr Integer -> repr Integer -> repr Bool >>> newtype P repr t = P { unP :: Bool -> repr t } >>> instance Ints repr => Ints (P repr) where >>> int n = P $ \ s -> if s then int n else (.-.) (int n) >>> (.-.) n = P $ unP n . not >>> n .+. m = P $ \ s -> unP n s .+. unP m s >>> n .*. m = P $ \ s -> unP n s .*. unP m s >>> n .<=. m = P $ \ s -> unP n s .<=. unP m s After pushing down negations I'd like to distribute (.*.) over (.+.). [1] leaves it as an exercise, so it can't be that hard, but I don't get it... Anyone knows how I could do it? [1]: <http://okmij.org/ftp/tagless-final/course/lecture.pdf> thanks, -- -- matteo