How do I determine if a list created using a lambda expression is null?

Hi Folks, I have a lambda expression that can be used to construct a list of values: cons = (\a -> (\b -> (\f -> f a b))) Here is an example that uses cons to construct "hello" hello = cons 'h' (cons 'e' (cons 'l' (cons 'l' 'o'))) And here is a lambda expression that returns the tail of a list created using cons: tail' = (\c -> c (\a -> (\b -> b))) I would like to create a function that computes the length of a cons-created list: length' = \xs -> if ( null' xs ) then 0 else length' (tail' xs) + 1 How would I define null' to determine if a cons list is empty? null' = ??? /Roger

You need to define your empty list first, I'd suggest something along the lines of: nil = \f -> True Does that help with your definition for null? Bob if (*ra4 != 0xffc78948) { return false; } On 24 Oct 2011, at 21:21, Costello, Roger L. wrote:
Hi Folks,
I have a lambda expression that can be used to construct a list of values:
cons = (\a -> (\b -> (\f -> f a b)))
Here is an example that uses cons to construct "hello"
hello = cons 'h' (cons 'e' (cons 'l' (cons 'l' 'o')))
And here is a lambda expression that returns the tail of a list created using cons:
tail' = (\c -> c (\a -> (\b -> b)))
I would like to create a function that computes the length of a cons-created list:
length' = \xs -> if ( null' xs ) then 0 else length' (tail' xs) + 1
How would I define null' to determine if a cons list is empty?
null' = ???
/Roger
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (2)
-
Costello, Roger L.
-
Thomas Davie