[clean-list] Understanding Generics
Alexsandro Soares
a_s_soares at yahoo.com.br
Wed Aug 2 19:20:28 MEST 2006
Arjen,
I'm trying to make a Clean version of the genetic
programming system originally written in Haskell using
PolyP. The online reference is:
http://www.cs.chalmers.se/~patrikj/poly/others/geneticalgorithmsinhaskellwithpolytypicprogramming.ps.gz
There, the author uses a paramorphism to implement the
function "sub" (called "scan", in the original
system), in this way:
------------------------------------------------
--para :: Regular d => (d a -> FunctorOf d a b -> b)
-> d a -> b
para i x = i x (fmap id (para i) (out x))
polytypic fchildren :: (f a [b] -> [b])
= case f of
Const t -> \x -> []
Empty -> \x -> []
Par -> \x -> []
Rec -> \x -> x
f * g -> \(x,y) -> fchildren x ++ fchildren y
f + g -> either fchildren fchildren
--scan :: d a -> [d a]
scan = para (\x -> \y -> x : fchildren y)
----------------------------------------------
I think the result of sub [[1, 2], [3], [4, 5, 6]]
is
[ [[1, 2], [3], [4, 5, 6]],
[[3], [4, 5, 6]],
[[4, 5, 6]],
[[]]
]
But I'm not sure.
Regards,
Alex
--- Arjen van Weelden <A.vanWeelden at cs.ru.nl>
escreveu:
> Sorry for the reply to self.
>
> There is another issue with this not so elegant
> solution:
> it give a run-time error on lists of lists, e.g.,
> [[Int]].
> Alex, what do you want in this case?
> What should be the result of sub [[1, 2], [3], [4,
> 5, 6]]?
>
> regards,
> Arjen
>
_______________________________________________________
O Yahoo! está de cara nova. Venha conferir!
http://br.yahoo.com/preview
More information about the clean-list
mailing list