[Haskell-cafe] Thompson's Exercise 9.13
Kaoru Hosokawa
khosokawa at gmail.com
Sat Apr 16 22:10:33 EDT 2005
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 at gmail.com
More information about the Haskell-Cafe
mailing list