Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^15: World's shortest intro to function programming

by BrowserUk (Patriarch)
on Jun 20, 2005 at 19:38 UTC ( [id://468467]=note: print w/replies, xml ) Need Help??


in reply to Re^14: World's shortest intro to function programming
in thread Thread on Joel on software forum : "I hate Perl programmers."

I can't even think what chapter it would be in.

The implementation is shown on the lecture slides for CH.3.

I just assumed (probably wrongly) that it was drawn from the book. I will go find the book next time I'm in town (rare) and give it a good browse. I will say that I have learnt a lot from just the slides already and I thankyou for bringing it to my attention.

It's that 2D syntax thing biting you again. You need to indent the "name <- getLine" line in to match up with everything else...

Hmmm. Seems I used the tab key instead of the space key for that one line. Looked fine in my editor and I didn't notice the difference in the post till I just looked back. I'm still working on my editor configuration for Haskell. It now converts tabs to spaces on save.

The error message could be a little more informative.

GetArgs

I looked under System.Console; System.IO; System.Info; System.Process; System.Environment didn't get my attention. Before I discovered functional programming, I always thought there must be a better way of creating programs then I was currently doing.

Likewise, I really want to like Haskell. My point was not that Perl was perfect or that Haskell was in anyway limited--Autrijus is proving otherwise every day. I'd just really like to see a reasonably simple but complete program developed from start to finish, by a competent Haskell programmer, as a way of getting a step up into the use of the language.

With most Algol like languages, it is fairly easy for me to pick up the source to a program who's function I understand and learn by reading and modifying it. I've tried this with Haskell, but it is so different, not just in the layout, but the entire way of structuring the program, that even the simplest of real world examples leaves me wondering where to start.

Simple example: When should I use data, when type or newtype?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^16: World's shortest intro to function programming
by Anonymous Monk on Jun 20, 2005 at 20:07 UTC
    Hmmm. Seems I used the tab key instead of the space key for that one line. Looked fine in my editor and I didn't notice the difference in the post till I just looked back.
    Significant whitespace can introduce some strange looking error messages (tabs are a tool of the devil).
    I've tried this with Haskell, but it is so different, not just in the layout, but the entire way of structuring the program, that even the simplest of real world examples leaves me wondering where to start.
    Yeah, its a real mindbending experience for a while, what with all the recursion and lack of state and partially applied functions and lazy evaluation and type inference and significant whitespace and unfamiliar syntax/precedence-rules/semantics (whew!). So I really encourage you to get a book to help you out on your new journey. (And if you get a used book and you don't like it, you can probably sell it back for about the same as you paid for it, less postage and tax)
    Simple example: When should I use data, when type or newtype?
    If you know C, think of "data" like "struct" and "type" like "typedef". A "newtype" is just like "data", with only one type constructor (which gets optimized away at runtime).
Re^16: World's shortest intro to function programming
by Anonymous Monk on Jun 20, 2005 at 20:49 UTC
    Also, you might want to look at the Computer Language Shootout. There are a lot of little programs implementated in a lot of languages which can give you some code examples to look at. (although I hesisitate a little because of the shootout's emphasis on performance over simple and clear code)
Re^16: World's shortest intro to function programming
by kelan (Deacon) on Jun 21, 2005 at 14:44 UTC

    I'd just really like to see a reasonably simple but complete program developed from start to finish, by a competent Haskell programmer, as a way of getting a step up into the use of the language.

    You may have seen this already, but nothingmuch was also fed-up with having no real-world examples in the Haskell tutorials. So to help himself learn, and maybe help out the other like-minded imperative programmers, he's developing a Forth compiler targetting Parrot, in a tutorial-like format. It starts off simple and builds up, so it's not too difficult to follow. Give it a look if you haven't already.

    Simple example: When should I use data, when type or newtype?

    The Anonymous Monk's reply to this question is clear and concise, but for anyone following along that doesn't know C, here's a more verbose answer.

      probably what confused me the most about the data construct when I started learning it was that the examples used the same word for the typename and the data constructor, so it was unclear that they are actually separate ideas.

      I think you hit the nail on the head. The use of single character identifiers--in the documentation, I don't have so much of a problem with their use for local vars in actual code--is a big barrier to understanding.

      If the docs (and maybe the type signatures generated by ghci) used somewhat more verbose identifiers (typeA instead of just a or funcA instead of f or p etc.), I think it would make it easier to assimilate.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://468467]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 18:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found