A few observations Re: Clean
Adrian Hey
ahey@iee.org
Sun, 03 May 1998 09:45:18 +0100 (BST)
On Sat 02 May, I wrote:
> This provides a way to give Clean a 'Cons' operator similar to
> most other functional languages..
>
> (:>) infixr 5
> (:>) h t :== [h:t]
>
> Page 93 of the Language report (V1.2) gives precisely this example
> to illustrate Macro use. So people porting from other languages to
> Clean can write functions like this...
>
> mapit f [] = []
> mapit f (x:>xs) = f x :> mapit f xs
>
> ..which will save a having to put in all those [..].
Oh dear, maybe not. I think I might have found a compiler bug.
The following code crashes the compiler (on my Mac at least).
// ------------------------------------
(:>) infixr 5
(:>) h t :== [h:t]
:: BTree a = EmptyBT | RootBT (BTree a) a (BTree a)
// Make a binary tree from the first 'n' elements of a sorted
// list 'as' and return the unconsumed list. 0<=n<=(length as)
makBT :: !Int [a] -> (BTree a, [a])
makBT 0 as = (EmptyBT , as)
makBT n as = let rn = n >> 1
ln = n-rn-1 // ln+rn+1=n
// ??? the next line causes compiler crash..
(leftBT , a:>as1) = makBT ln as
// But its ok if I use this instead..
// (leftBT ,[a:as1]) = makBT ln as
(rightBT,as2 ) = makBT rn as1
in (RootBT leftBT a rightBT, as2)
// ------------------------------------
This may or may not be valid Clean. I think it is, but even
if it isn't I think the compiler should stop gracefully with
an appropriate error message.
Regards
--
Adrian Hey