<!doctype html public "-//W3C//DTD W3 HTML//EN">
<html><head><style type="text/css"><!--
blockquote, dl, ul, ol, li { padding-top: 0 ; padding-bottom: 0 }
--></style><title>Re: [clean-list] strictness annotation introduces
type err</title></head><body>
<div>Erik Zuurbier wrote:</div>
<blockquote type="cite" cite><font face="Arial" size="-1"
color="#000000">The following gives a type error
message:</font></blockquote>
<blockquote type="cite" cite> </blockquote>
<blockquote type="cite" cite>splitLine :: ![!Char] -> [String]<br>
splitLine cs<br>
# (frst,rest) = span (\a->a<>';') cs<br>
# str = {c\\c<-frst}<br>
= case rest of<br>
[] = [str]</blockquote>
<blockquote type="cite" cite> _ = [str:splitLine
(drop 1 rest)]</blockquote>
<blockquote type="cite" cite> </blockquote>
<blockquote type="cite" cite>The error messages are:</blockquote>
<blockquote type="cite" cite>"Type error
[tabellen.icl,53,splitLine]:"argument 1 of splitLine" cannot
unify types:<br>
[!Char]<br>
[v20]<br>
Type error [tabellen.icl,51,splitLine]:"argument 2 of span"
cannot unify types:<br>
[Char]<br>
[!Char]<br>
Type error [tabellen.icl,40,procFile]:"argument 1 of splitLine"
cannot unify types:<br>
[!Char]<br>
[v20]"</blockquote>
<blockquote type="cite" cite> </blockquote>
<blockquote type="cite" cite>When I remove the second ! in the type,
the errors disappear. I thought that strictness annotations were not
supposed to introduce type errors.</blockquote>
<div><br></div>
<div>The ! after [ or { in a list or array type is not a strictness
annotation,</div>
<div>but part of the name of the type. [!a] and [a] are different
types</div>
<div>(and so are {!a} and {a}).</div>
<div><br></div>
<div>The compiler does not convert [a] to [!a] (or [!a] to [a]),
because that</div>
<div>would usually be too expensive (but it does for tuples).</div>
<div><br></div>
<div>Rewriting to (using overloaded list constructors):</div>
<div><br></div>
<div>import StdOverloadedList</div>
<div><br>
splitLine :: ![!Char] -> [String]<br>
splitLine cs<br>
# (frst,rest) = Span (\a->a<>';') cs<br>
# str = {c\\c<-frst}<br>
= case rest of<br>
[|] = [|str]<br>
_ = [|str:splitLine (Drop 1 rest)]<br>
</div>
<div>should have fixed the problem, but it didn't because the
definition of</div>
<div>Span in StdOverloadedList is incorrect. It should be:</div>
<div><br></div>
<div>Span p l :== span l<br>
<x-tab> </x-tab>where<br>
<x-tab>
</x-tab><x-tab> </x-tab>span
list=:[|x:xs]<br>
<x-tab>
</x-tab><x-tab>
</x-tab><x-tab> </x-tab>| p
x<br>
<x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab><x-tab> </x-tab>#
(ys,zs) = span xs<br>
<x-tab>
</x-tab><x-tab>
</x-tab><x-tab>
</x-tab><x-tab> </x-tab>=
([|x:ys],zs)<br>
<x-tab> </x-tab><x-tab>
</x-tab><x-tab>
</x-tab><x-tab> </x-tab>=
([|],list)<br>
<x-tab>
</x-tab><x-tab> </x-tab>span
[|]<br>
<x-tab>
</x-tab><x-tab>
</x-tab><x-tab> </x-tab>=
([|], [|])<br>
</div>
<div>(the |'s were missing). I have fixed this in our development
version.</div>
<div><br></div>
<blockquote type="cite" cite> 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?</blockquote>
<div><br></div>
<div>We have no plans to change this. Converting is too expensive
because it</div>
<div>usually means traversing or copying the entire list. Overloading
the</div>
<div>default list type and constructors will cause too much
overloading that</div>
<div>cannot be resolved.</div>
<div><br></div>
<div>Kind regards,</div>
<div><br></div>
<div>John van Groningen</div>
</body>
</html>