Development Function that will print itself

Discussion in 'Software' started by ozstrike, 16 Apr 2010.

  1. ozstrike

    ozstrike yip yip yip yip

    Joined:
    19 Sep 2004
    Posts:
    2,946
    Likes Received:
    11
    Hey guys, got a bit of a coursework problem here, which I can't for the life of me seem to figure out. I know you don't want to be helping people do their coursework, so I'll take any hints, or even code in another language to help me.

    I need, in Haskell, to write a function that will print it's own definition. I have no idea where to go with this! Obviously, the more you write, the more you have to print out.

    The only thing I can think of at the minute is something clever with string multiplication, but I"m really stuck. Any help?
     
  2. capnPedro

    capnPedro Hacker. Maker. Engineer.

    Joined:
    11 Apr 2007
    Posts:
    4,381
    Likes Received:
    241
    You mean like a quine?
    Couldn't you write it in a real language, like C where you can use the preprocessor? :lol:


    Solution (don't read it unless you want to cheat):
    main=putStr(p++show(p))where p="main=putStr(p++show(p))where p="
     
  3. ozstrike

    ozstrike yip yip yip yip

    Joined:
    19 Sep 2004
    Posts:
    2,946
    Likes Received:
    11
    Awesome, I knew there'd be a name for it. That haskell solution is very simliar to what I was attempting, I was close!

    Thanks.
     

Share This Page