Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Haskell

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).

Name: Anonymous 2007-10-04 1:19

$ shift . ( map ! car unshift $^#%^ ) :: cdr -> sussman

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.

Name: Anonymous 2007-10-04 5:59

>>1
id Haskell prelude function recursively
whut?

id is (lambda (x) x)

Name: Anonymous 2007-10-04 6:39

Tell your professor that he can pick between an "id" written recursively, and one that TERMINATES.

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

Name: Anonymous 2007-10-04 7:53

>>6
You forgot singleton enterpriseMissionCriticalIdentityFunctionClassFactoryBridge
Wait, what

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.

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

Name: Anonymous 2007-10-04 14:23


id :: a -> a
id = id -- POINT FREE

Name: Anonymous 2007-10-04 18:30

>>10
Pointless

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.

Name: Anonymous 2010-12-06 9:26

Back to /b/, ``GNAA Faggot''

Don't change these.
Name: Email:
Entire Thread Thread List