Haskell
1
Name:
Anonymous
2007-10-03 23:44
Hi /prog/, i'm doing a basic programming course at uni and the lecturer has set a challenge to write the id Haskell prelude function recursively:
id :: a -> a
id x = x
I can't think of a way to do this which is meaningful, any ideas (this isn't marked or anything so i'm not in any way cheating).
2
Name:
Anonymous
2007-10-04 1:19
$ shift . ( map ! car unshift $^#%^ ) :: cdr -> sussman
3
Name:
Anonymous
2007-10-04 5:14
Spit in your lecturers face and tell him he 1) Doesn't understand recursion 2) Hasn't read SICP.
4
Name:
Anonymous
2007-10-04 5:59
>>1
id Haskell prelude function recursively
whut?
id is (lambda (x) x)
5
Name:
Anonymous
2007-10-04 6:39
Tell your professor that he can pick between an "id" written recursively, and one that TERMINATES .
6
Name:
Anonymous
2007-10-04 7:33
CAPTAIN ENTERPRISE to the rescue!
enterpriseMissionCriticalIdentityFunction :: a -> a
enterpriseMissionCriticalIdentityFunction x =
enterpriseNTierIdentityFunction x null null null null null null null 69 -- Scalable!
where
enterpriseNTierIdentityFunction x _ _ _ _ _ _ _ n
| n > 0 = enterpriseNTierIdentityFunction x null null null null null null null (n - 1)
| otherwise = x
main = do
print $ enterpriseMissionCriticalIdentityFunction 1
7
Name:
Anonymous
2007-10-04 7:53
>>6
You forgot singleton enterpriseMissionCriticalIdentityFunctionClassFactoryBridge
Wait, what
8
Name:
Anonymous
2007-10-04 9:16
>>6
(OP) Thankyou Captain Enterprise, shall i take this to mean that i was correct in assuming that there is no meaningful way to do this then? I'll post his answer when he gives it so anyone who is interested can take a gander.
9
Name:
Anonymous
2007-10-04 12:35
shall i take this to mean that i was correct in assuming that there is no meaningful way to do this then?
Of course.
____
Sincerely,
Captain. Obvious, on behalf of Captain Enterprise
10
Name:
Anonymous
2007-10-04 14:23
id :: a -> a
id = id -- POINT FREE
11
Name:
Anonymous
2007-10-04 18:30
12
Name:
Anonymous
2007-10-05 10:34
The "correct" solution was
id :: a -> a->
id x = const x id
or
id x = const x (id x)
or
id x = if True then x else id x
so i guess there was no meaningful solution after all.
14
Name:
Anonymous
2010-12-06 9:26
B a c k t o / b / , ` ` G N A A F a g g o t ' '