I tried to find out how Haskell understands the "lambda" programming.
Here is the script for the length of a list.
This is the so-called continuation passing stile, I believe.

lng :: [a] -> Int

lng =  (\ xs -> 
         ( (\xs c -> if null xs then 0  else  1+(c (tail xs) c) )
             xs 
             (\xs c -> if null xs then 0  else  1+(c (tail xs) c) )
         )
       )

This script is remarkable for it expresses the recursion and still
does not contain the calls for the function names  (we might avoid 
(+) too).
It stands for

lng xs =  l xs l  where
                l xs c =  if null xs then 0  else  1+(c (tail xs) c)
---------------------------------------------------------------------

But Haskell fails to find the type of the variable  c.

I was able to find it myself only by introducing the new data
constructor and changing the script:


data  C a =  C ([a] -> C a -> Int)
                       ---

lng xs =  
  (\ xs (C c)-> if null xs then 0  else 1+(c (tail xs) (C c)))
    xs
    (C  (\ xs (C c)-> if null xs then 0  else 1+(c (tail xs) (C c))) )
    

--Test:
main =  print (show (map lng  [[],[1],[1,2],[1,2,3],[1,2,3,4]] )  )

---------------------------------------------------------------------


Could anybody answer the questions:

1) Is it a principal feature that Haskell cannot derive this type for
   `c' ?
2) Is it necessary to introduce a new constructor to express recursion
   via continuation in the above task ?



Thank you.

Sergey Mechveliani       [EMAIL PROTECTED]



Reply via email to