[<<][meta][>>][..]
Fri Aug 26 16:38:39 CEST 2011
Tuples to lists
The tuples are good for creating heterogenous collections that can
still be composed without fear of run time errors. However, once type
checked the compilation to output syntax can be allowed to strip a lot
of information.
One of those is the tuple structure for the states. We just need
lists in the end because all the types are removed and only syntax
remains. Once we have lists we can use simpler run-time iteration.
Something like the following, but then working..
class Show s => TupleShow s where
tupleShow :: s -> [String]
tupleShow x = [show x]
instance TupleShow () where
tupleShow () = []
instance (TupleShow a, TupleShow b) => TupleShow (a,b) where
tupleShow (a,b) = tupleShow a ++ tupleShow b
Ah the trick is to not let TupleShow depend on Show since that gives
conflicting instances. Still I have some trouble with the
existentials..
Ok, I've moved to a different composite state type StateProd to keep
general tuples and compisite states separate. Also moved the
stateShow operation into SigState:
class Show s => (SigState s) where
stateIndex :: Int -> s -> (Int, s)
stateShow :: s -> [String]
stateIndex n s = (n+1, s)
stateShow s = [show s]
instance (SigState a, SigState b) => SigState (StateProd a b) where
stateIndex n0 (StateProd (a, b)) = (n2, (StateProd (a', b'))) where
(n1, b') = stateIndex n0 b
(n2, a') = stateIndex n1 a
stateShow (StateProd (a,b)) = stateShow a ++ stateShow b
instance SigState () where
stateIndex n () = (n, ())
stateShow () = []
instance SigState Int
instance SigState Integer
instance SigState Double
If renaming is required the stateIndex method needs to be overwritten.
It looks like I'm done with the hard work:
*Main> test3
([["s2","s1","s0"],["0","0","0"],["(((i + s0) + s1) + s2)","((i + s0) + s1)","(i + s0)"]],["(((i + s0) + s1) + s2)"])
*Main> map head $ fst test3
["s2","0","(((i + s0) + s1) + s2)"]
Next: find a way to combine with sharing. It's not clear to me where
exactly that can be plugged.
[Reply][About]
[<<][meta][>>][..]