[<<][meta][>>][..]

Mon Aug 8 16:12:11 CEST 2011

## Interface question: a -> b -> M c or M a -> M b -> M c

The Haskell LLVM library uses (something like) a -> b -> M c, which
enables the use of the do notation to map to SSA variable binding.
The Symantics language however uses expressions, not SSA form, which
means the representation needs to be M a -> M b -> M c.
That already answers the question: Why doesn't Symantics have the
former type? ( Because it supports espressions. ) LLVM is already
SSA, while Symantics can be converted to SSA by fixing an order in the
2-op lift function. This is exactly what is done in SymAsm:
op2 t fn (Asm x) (Asm y) = Asm $ do
vx <- x
vy <- y
op t fn [vx, vy]
where `op' creates a new value in the State Continuation monad.
For LLVM I'm trying this, which fails due to too general type
restrictions:
_iadd (SSA ma) (SSA mb) = SSA $ do
a <- ma
b <- mb
add a b
_iadd
:: (ABinOp a b (v c), IsArithmetic c) =>
SSA r a t -> SSA r b t1 -> SSA r (v c) t2
Can these r & a parameters just be dropped?
I tried the following[1]:
data SSA t = forall r a. SSA { unSSA :: CodeGenFunction r a }
But then the instance declaration gives problems. This is for another
time; the type mojo is going over my head again..
Ha, a solution to the problem is explained in [2].
What I take from this is that it's probably simpler to turn everything
upside down anyway: start with a monadic interface, i.e. make
Symantics monadic so do notation can be used for let, and then define
num classes for that monad.
Hmm... this defines Num classes for all variants of types that get
built up, but doesn't try to force things into a simpler type
altogether, which is what I'm trying to do.
Pff..
The solution seems to be to fix the type:
_iadd ::(ABinOp a a a, IsArithmetic a) => SSA r a t -> SSA r a t -> SSA r a t
_iadd (SSA ma) (SSA mb) = SSA $ do
a <- ma
b <- mb
add a b
[1] http://en.wikibooks.org/wiki/Haskell/Existentially_quantified_types
[2] http://augustss.blogspot.com/2009/01/llvm-arithmetic-so-we-want-to-compute-x.html

[Reply][About]

[<<][meta][>>][..]