[clean-list] questions from a beginner

Edsko de Vries devriese at cs.tcd.ie
Sat Apr 28 17:06:50 MEST 2007


Hi,

> 1. Is there a way to get the deducted type information?
> For example:
> myFunc n x
>    | n==0    = 1.0
>    | n>0    = x * myFunc (n-1) x
>    | otherwise = abort("Error n<0")
> Ok, it is a simple one, and the type must be myFunc :: Int Real -> Real
> So I want to know what the compiler "thinks" about it...

It depends on which platform you are using. If you are using the Clean
GUI on WIndows or Mac, you can select somewhere in the module options (I
believe) that you want to see all the inferred types. If you are using
the command line compiler on Linux, use the -lat option.

> 2. What is wrong in my code?
> *In CleanBookI.pdf, page 37 an example:
>    Start = takeWhile ((<>) 0.0) (iterate (\x = x/10.0) 1.0)
> In Exercise No 2:
>    "Rewrite the program such that it only prints the smallest number 
> that is different from
>    zero using the function until."
> *My first solution try:
>    smallestRealv2 = until (\x = x/10.0 == 0.0 ) (\x = x/10.0) 1.0
>    Start = smallestRealv2
> It prints: 0
> *Second try:
>    smallestRealv3 = until (smrAux) (\x = x/10.0) 1.0
>        where smrAux x       
>                |  (x/10.0) <> 0.0   =   False       
>                |  otherwise         =   True       
>    Start = smallestRealv2
> This one also prints: 0
> The original example works, of course, and the last number in the list 
> is about 9.8813E-324,
> so I expected this result. What is wrong?

This one I'm not sure about. Your solution seems correct, and when I try
your solution in Haskell I do get the last number in that list. Not sure
what's happening here.

> 3. What is '.' (dot) in type definitions?
> I know that ! is for strict, and * for unique.
> (I don't really know yet what uniqueness means exactly, but it is an 
> other story... I'm not there yet)
> For example in CleanBookI.pdf, page 206:
>    filter :: (a -> .Bool) !.[a] -> .[a]      // Drop all elements not 
> satisfying pred
> And if we are here, what is the 'u:' prefix? example: insertAt :: !Int 
> .a u:[.a] -> u:[.a]

Let me answer these two questions in one go. In a uniqueness type
system, types can be unique or non-unique, or they can be polymorphic in
their uniqueness. In other words, the uniqueness of the type may be a
variable (like u). The "." is a notational convention, and just means
"there is an uniqueness variable here, but its name does not matter".
Part of the convention is also that if a type variable appears in more
than one place (for example, .a -> .a), then the dot refers to the
_same_ uniqueness variable in all cases.

Hope that helps,

Edsko

> 
> 
> Thanks,
> Markó Csaba
> 
> _______________________________________________
> 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