Functional Dependencies / Type Families - AST?

The way you have defined the Lit constructor will prevent you from projecting out the value it contains, regardless of how you define the projection function.

The way you have defined the Lit constructor will prevent you from projecting out the value it contains, regardless of how you define the projection function. Let's look at the constructor's type: Lit :: Prim l => l -> E The type variable l appears in the parameters, but not the return type. That means that when you construct a Lit, you put in a value of some type that's a member of Prim and then permanently forget what its type was.

I'm not sure how you want to eliminate pattern matching and unwrapping of value constructors. You basically have two choices for how to do projections: Project values at run time, using pattern matching or something equivalent to it. Project values at compile time, by proving using the type system that the data type you have is equal to the data type you want.

There are reasons to go with compile-time proofs, but it doesn't look like you have any of those reasons.

2 It sounds sorta like OP wants Data. Dynamic but sorta not. I'm not really sure.

– ephemient Dec 10 '10 at 5:49 Yes, that is exactly the problem. I want to be able to reference E, as it is the expression type, but I lose type information necessary for using inj and proj in the process. Option (2) sounds interesting, but I can't find reference material.Thanks.

– danportin Dec 11 '10 at 6:38 I guess many of Haskell tutorials describe Expression with using "Phantom types" pattern. I.e. Data E l where Lit :: Prim l => l -> E l; Bin :: E l -> E l -> E l.

If you'll need to infer expression type for binary operation you can use additional typeclass with func. Deps.(or typefamily) class BinOp a be c | a be -> c and then Bin :: BinOp a be c => E a -> E be -> E c. – ony Feb 8 at 7:05.

If you still want to stick with idea of polymorphic E. You can use polymorphic functions: withUnlit :: E -> (forall l . Prim l => l -> b) -> be withUnlit (Lit a) f = f a But the only thing you can do (with traits you've given to Prim l) is: showE :: E -> String showE e = withUnlit e show And inj and proj.

But you have no way to work with Val l except of using some Data. Dynamic (if that is what I think).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions