[clean-list] type reporting

Jerzy Karczmarczuk karczma@info.unicaen.fr
Wed, 17 Dec 2003 10:18:29 +0100


This is a multi-part message in MIME format.
--------------060006040209030503020608
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Maestros,
Some simple questions concerning the behaviour of your type reporter.
It is very nice to have a readable type report, which can then be
copied/pasted to the definition module, etc.

But quite a time ago I discovered that it writes sometimes some types
which are illegal, which are not accepted by the compiler itself. So,
it was most probably some cosmetic error in writing down the type.
That error has probably been corrected, I can't track it anyway. But
I have others.
I attach the full program. It contains a function fractnoise which
has an internal one: 'midpoint'. It begins like that:


fractnoise kappa nstages seed = fr seed where
   fctr = 0.5^kappa
   fr seed
     # (l,seed) = midpoint [#0.0,0.0] 1.0 nstages seed
     = l ++| fr seed
   midpoint l _ 0 seed = (l,seed)
   midpoint (xs=:[#x0:xq]) amp n seed
     #! (l1,seed) = mdsp xq xs [#x0] amp seed
...............

and the type inferrer reports:

midpoint :: Real u:[#Real] Real !Int Int -> (v:[#Real],Int), [u <= v]

For goodness' sake, the function midpoint accepts 4 parameters, not 5.
What the first Real is doing there? The first argument is a list.

*************************************************************

Since I overload lists (in fact I use [#Real] only), the typechecker
generates some internal objects, in particular:

map_ :: (u:a -> v:b) !w:(c u:a) -> x:(d v:b) | List; c a & List; d b, [w <= u,x 
<= v]

Why this semicolon after List? It is not accepted by the compiler.
Also, another function:


readWav fname world
  # (bool,file,world) = fopen fname FReadData world
  ....................

produces

readWav :: {#.Char} *a -> *(.{#Char},*a) | FileSystem; a

Again a spurious semicolon.

Thank you.


Jerzy Karczmarczuk

--------------060006040209030503020608
Content-Type: text/plain;
 name="purebug.icl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="purebug.icl"

module purebug

import StdEnv
import StdStrictLists, StdOverloadedList

class (*>)  infixr 7 t   :: !Real (t Real) -> (t Real)
instance *> [#] where
 (*>) x l = Map (\s -> x*s) l

ZipWith op l1 l2 :== ZipWith l1 l2 where
  ZipWith [|a:as] [|b:bs] = [|(op a b) : ZipWith as bs]
  ZipWith as bs            = [|]

instance + [#Real]
where
 (+) l1 l2 = ZipWith (+) l1 l2
instance - [#Real]
where
 (-) l1 l2 = ZipWith (-) l1 l2 

rand1_s seed
 # seed = 599479 + seed*25781083
 = (toReal seed/2147483648.0,seed)
 
fractnoise kappa nstages seed = fr seed where
  fctr = 0.5^kappa
  fr seed
    # (l,seed) = midpoint [#0.0,0.0] 1.0 nstages seed
    = l ++| fr seed
  midpoint l _ 0 seed = (l,seed)
  midpoint (xs=:[#x0:xq]) amp n seed
    #! (l1,seed) = mdsp xq xs [#x0] amp seed
    =  midpoint l1 (amp*fctr) (n-1) seed 
  mdsp [#x1:xq] [#y0:yq] tmp a seed
    #! (r,seed) = rand1_s seed
    #! z = 0.5*(x1+y0) + r*a
    =  mdsp xq yq [#x1 : z : tmp] a seed
  mdsp _ _ tmp _ seed = (tmp,seed)
  
readWav :: {#.Char} *a -> *(.{#Char},*a) | FileSystem; a 
readWav fname world
 # (bool,file,world) = fopen fname FReadData world
 | not bool = abort "Cannot open Wav file"
 # (hrif,file) = freads file 4
 | hrif <> "RIFF" = abort "Not a RIFF file"
 # (tbool,flen,file) = freadi file
 # (hwav,file) = freads file 4
 | hwav <> "WAVE" = abort "Not a WAVE file"
 # totlen = flen+8
 # (ok2,file) = fseek file 0 FSeekSet
 # (data,file) = freads file totlen
 # (cbool,world) = fclose file world
 = (data,world)
 
 
Start = "OK"





--------------060006040209030503020608--