1 Feb 2013 09:09
why GHC cannot infer type in this case?
<oleg <at> okmij.org>
2013-02-01 08:09:02 GMT
2013-02-01 08:09:02 GMT
Dmitry Kulagin wrote:
> I try to implement little typed DSL with functions, but there is a problem:
> compiler is unable to infer type for my "functions".
One way to avoid the problem is to start with the tagless final
representation. It imposes fewer requirements on the type system, and
is a quite mechanical way of embedding DSL. The enclosed code
re-implements your example in the tagless final style. If later you
must have a GADT representation, one can easily write an interpreter
that interprets your terms as GADTs (this is mechanical). For more
examples, see the (relatively recent) lecture notes
http://okmij.org/ftp/tagless-final/course/lecture.pdf
{-# LANGUAGE TypeOperators, KindSignatures, DataKinds #-}
{-# LANGUAGE NoMonomorphismRestriction, TypeFamilies #-}
module TestExp where
-- types of DSL terms
data Ty = Int16 | TFun [Ty] Ty | TSeq [Ty]
-- DSL terms
class Exp (repr :: Ty -> *) where
int16:: Int -> repr Int16
add :: repr Int16 -> repr Int16 -> repr Int16
decl :: (repr (TSeq ts) -> repr t) -> repr (TFun ts t)
call :: repr (TFun ts t) -> repr (TSeq ts) -> repr t
(Continue reading)
RSS Feed