[<<][meta][>>][..]
Mon Dec 12 21:11:36 EST 2011
Indexing
See, I'm trying to make two types, one indexed with ((), x) and one
with Int -> x. Why not keep it at one and build an Array instance for
(Code (Int -> x))?
class TMLprim t where
primType :: t -> TypeName
primOrder :: t -> Int
primOrder _ = 0
instance TMLprim Tbool where primType _ = ABool
instance TMLprim Tint where primType _ = AInt
instance TMLprim Tfloat where primType _ = AFloat
instance TMLprim Tvoid where primType _ = AVoid
instance TMLprim t => TMLprim (Tint -> t) where
primType _ = primType (undefined :: t)
primOrder _ = 1 + (primOrder (undefined :: t))
This gives a straightforward Array instance
instance Array MCode' Code ((->) Tint) t where
_get (Code (Ref a@(Var (Type base (dim:dims)) _))) (Code i) =
mVarTyped (Type base dims) (Code $ Get a i)
_set (Code (Ref a)) (Code i) (Code e) =
mVoid $ Code $ Set a i e
Then the TypeOf becomes straightforward:
instance TMLprim t => TypeOf (Code t) where
typeOf _ = Type (primType (undefined :: t)) dims where
dims = map (\_ -> ()) [1..order]
order = primOrder (undefined :: t)
[Reply][About][<<][meta][>>][..]