[clean-list] strictness annotation introduces type error

John van Groningen johnvg at cs.ru.nl
Fri Nov 6 17:11:13 MET 2009


Erik Zuurbier wrote:
>The following gives a type error message:
>
>splitLine :: ![!Char] -> [String]
>splitLine cs
>  # (frst,rest) = span (\a->a<>';') cs
>  # str = {c\\c<-frst}
>  = case rest of
>    [] = [str]
>    _ = [str:splitLine (drop 1 rest)]
>
>The error messages are:
>"Type error [tabellen.icl,53,splitLine]:"argument 1 of splitLine" 
>cannot unify types:
>  [!Char]
>  [v20]
>Type error [tabellen.icl,51,splitLine]:"argument 2 of span" cannot 
>unify types:
>  [Char]
>  [!Char]
>Type error [tabellen.icl,40,procFile]:"argument 1 of splitLine" 
>cannot unify types:
>  [!Char]
>  [v20]"
>
>When I remove the second ! in the type, the errors disappear. I 
>thought that strictness annotations were not supposed to introduce 
>type errors.

The ! after [ or { in a list or array type is not a strictness annotation,
but part of the name of the type. [!a] and [a] are different types
(and so are {!a} and {a}).

The compiler does not convert [a] to [!a] (or [!a] to [a]), because that
would usually be too expensive (but it does for tuples).

Rewriting to (using overloaded list constructors):

import StdOverloadedList

splitLine :: ![!Char] -> [String]
splitLine cs
  # (frst,rest) = Span (\a->a<>';') cs
  # str = {c\\c<-frst}
  = case rest of
    [|] = [|str]
    _ = [|str:splitLine (Drop 1 rest)]

should have fixed the problem, but it didn't because the definition of
Span in StdOverloadedList is incorrect. It should be:

Span p l :== span l
	where
		span list=:[|x:xs]
			| p x
				# (ys,zs) = span xs
				= ([|x:ys],zs)
				= ([|],list)
		span [|]
			= ([|], [|])

(the |'s were missing). I have fixed this in our development version.

>  Is this a disadvantage of the introduction, a couple of years 
>ago, of specific treatment of strict lists, spine strict lists etc.? 
>If so, will this disadvantage be lifted one time?

We have no plans to change this. Converting is too expensive because it
usually means traversing or copying the entire list. Overloading the
default list type and constructors will cause too much overloading that
cannot be resolved.

Kind regards,

John van Groningen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/clean-list/attachments/20091106/8b1364b0/attachment.html>


More information about the clean-list mailing list