On Feb 13, 2008 5:36 AM, Luke Palmer <[EMAIL PROTECTED]> wrote:
> On Feb 13, 2008 9:33 AM,  <[EMAIL PROTECTED]> wrote:
> > The approach is based on the final tagless representation. Here is our
> > DSL:
> >
> > > class Exp repr where
> > >    constant :: Int -> repr Int
> > >    variable :: String -> repr Int
> > >    add :: repr Int -> repr Int -> repr Int
> > >    sub :: repr Int -> repr Int -> repr Int
>
> This is very nice.  May I ask, though, what is the purpose of all the
> Ints appearing as arguments to repr here?  Looking over this code, it
> seems that it would work just as well if they were all omitted.

In this example, they could be omitted. But let's say you had a
language more than one type:

class Exp repr where
    constant :: Int -> repr Int
    variable :: String -> repr Int
    add :: repr Int -> repr Int -> repr Int
    sub :: repr Int -> repr Int -> repr Int

    true :: repr Bool
    false :: repr Bool
    and :: repr Bool -> repr Bool -> repr Bool
    less_than :: repr Int -> repr Int -> repr Bool
    if_ :: repr Bool -> repr a -> repr a -> repr a

The argument to repr prevents you from writing ill-typed code like
"if_ (variable "x") (constant 0) false".

-- 
Dave Menendez <[EMAIL PROTECTED]>
<http://www.eyrie.org/~zednenem/>
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to