[clean-list] Understanding Generics

Arjen van Weelden A.vanWeelden at cs.ru.nl
Thu Aug 3 16:38:08 MEST 2006


Hi Alex,

I don't think you can do this in Clean. PolyP can distinguish between 
types that are recursive occurrences (Rec) in a type definition, and 
those that are not (Par). It is hard to make such a distinction in Clean 
using the generic type information in the {|OBJECT of ...|} and {|CONS 
of ...|} instances. I can make it work for simple recursive types, but 
it is difficult for mutually and/or parametric recursive types.

I have an algorithm that recovers the actual/instantiated type, using 
unification on the types of all constructors of a type. It can tell, in 
the {|OBJECT|} instance, the difference between [Int] and [[Int]] for 
example, while the generic type information only tells you it's a [a]. 
Writing gsub using this information would mean merging these two 
algorithms, because a generic function in Clean cannot be overloaded in 
another generic function, and this gets very messy.

There doesn't seem to be an easy translation from PolyP to Clean.

regards,
	Arjen

Alexsandro Soares wrote:
> 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
> _______________________________________________
> clean-list mailing list
> clean-list at science.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/clean-list


More information about the clean-list mailing list