#haskell question about a course exercise

f x = (\y -> y) x

This is the identity function applies to the argument x. No problem here.

f x = \y -> y

I think this is invalid syntax. Lambda functions need to be wrapped in () ?

f x = (\y -> x) x

This one is unusual. I think it outputs x as if it were a constant. That is, the lambda function always outputs x, and doesn't calculate on y. Not sure about this one.....

@rzeta0 No, the second one is valid. No parentheses are required. f is a function that ignores its argument and returns the identity function.

You are correct about the third one. f ends up being just the identity function.

@byorgey

The solution given is that the second doesn't satisfy f 1 ==> 1

So if it isn't the syntax then I'm still trying to work out why it is wrong.

Is it that f 1 returns the identity function and not 1 ?

Quiz 3.12 at haskell.mooc.fi/part1#quiz-2

@dpwiz @byorgey

thanks again - I suspect this is common advice to beginners like me

@rzeta0 @dpwiz it is! I give that advice all the time to my students.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.