
16 Apr
2005
16 Apr
'05
10:10 p.m.
On 2005/04/16, at 12:57, Hamilton Richards wrote:
At 10:50 AM +0900 2005/4/16, Kaoru Hosokawa wrote:
My solution based on Bernie's solution:
init :: [a] -> [a] init xs = foldr (left (length xs)) xs xs
left :: Int -> a -> [a] -> [a] left n x xs | n == length xs = [] | otherwise = x : xs
I use the foldr return value for the empty list as the input itself. Use this value as a marker to signify that I am at the end of the list by checking its length.
Using length causes this definition of init to fail on infinite lists.
Oh. I haven't learned how to handle infinite data structures yet, but is init defined for infinite lists in the first place? -- Kaoru Hosokawa khosokawa@gmail.com