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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Costello, Roger L.
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


Reply | Threaded
Open this post in threaded view
|

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

Thomas Davie
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 at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20111024/46b2cf55/attachment.htm>