[Haskell-cafe] Re: Ideas of a polymorphic Tree in Haskell
Edgar Z. Alvarenga
edgar at ymonad.com
Thu May 13 18:01:16 EDT 2010
On Thu, 13/May/2010 at 18:57 +0100, Maciej Piechotka wrote:
> Hmm. What GDAT/existential do you use (for lazy people who do not want
> to read paper)?
The GADT that I refered was from my faileds attempts.
> How is it programmed in Lisp?
The paper don't give much details, but by what I undertood, if a random
generated program don't compile it's discarted.
> [...]
>
> Both compiles but I'm not sure if they are what you want.
What I want is to can create trees like:
U (a -> b) (U (c -> a) V)
Or:
B (a -> b -> c) (U (c -> a) V) (U (c -> b) V)
And convert this to a function c -> b. I think I have achieved this now,
but really don't understand exactly how it works. Look at this:
data Tree a b c where
B :: (a -> d -> b) -> Tree e a c -> Tree g d c -> Tree a b c
U :: (a -> b) -> Tree d a c -> Tree a b c
V :: (c -> d) -> Tree c d c
treeToFunc :: Tree a b c -> c -> b
treeToFunc (B f l r) = f <$> (treeToFunc l) <*> (treeToFunc r)
treeToFunc (U f u) = f.(treeToFunc u)
treeToFunc (V f) = f
The only problem is that I need to create (V id) in the last leaf
everytime:
*Main> let r = B (\x y -> (fromInteger x) + y) (U floor (V id)) (U (**2) (V id))
*Main> (treeToFunc r) 3
12.0
Do you see any way to simplify this solution?
Thanks,
Edgar
> Regards
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list