
From my perspective, the learning curve for Haskell seems to be near vertical. I've read several things on the web, and am working my way
(My apologies if this is off topic) Functional programming is completely new to me. I've been doing imperative programming for quite a while. through The Haskell School of Expression. Any words of wisdom? ADVthanksANCE, JJ Be Kind, Be Careful, Be Yourself

"JJ"
From my perspective, the learning curve for Haskell seems to be near vertical.
I also found it very steep. Keep on, read the "Gentle" Introduction, and start coding. Read the Haskell list, you'll understand more and more. Then read the Report... Good luck! Feri.

On Tue, Feb 11, 2003 at 08:07:42AM -0500, JJ wrote:
(My apologies if this is off topic)
Not at all!
Functional programming is completely new to me. I've been doing imperative programming for quite a while.
From my perspective, the learning curve for Haskell seems to be near vertical. I've read several things on the web, and am working my way through The Haskell School of Expression.
Any words of wisdom?
From a relative newbie to haskell (c.a. 6 months):
Haskell (and functional programming in general) requires a different way of thinking than imperative programming, which is a lot of what makes it difficult at first (the other thing being the weird syntax). The other thing to keep in mind is that due to haskell's pure functional character, things that are easy in imperative languages are often difficult or complicated in haskell, while things that are complicated in imperative languages are often simple in haskell, once you can wrap your brain around it. My recommendation, to start out, would be to try to focus on doing what is easy in haskell, which is NOT monads or IO. While in C, perl or whatever, "beginner" programs are typically 50% or more IO, what I would consider appropriate "beginner" programs in haskell would be mostly computation, with just enough IO to show you the output. On the other hand, quite contrary to this, the first haskell program I wrote was one to search and replace strings in text files, which is definitely not what haskell is best at (relative to the perl program I had written, which I was mimicking). Of course, that was because I was intentionally doing something I knew was probably painful in haskell, since if that wasn't too hard, I figured I'd go ahead and learn the language... I'm afraid I may have uselessly babbled on a bit. Mostly, my advice is to hang in there, and to try to concentrate on new ways of thinking about your problems. If you just try to program like you are used to doing, you may as well stick with an imperative language. btw, in my experience, I've found that a useful metric for how "functionally" I am thinking is the frequency with which I use map, foldl and friends. At first they seemed really confusing (and I still get couldn't tell you the difference between foldl and foldr without looking it up), but when you get used to them they can cut the quantity of code you need to write dramatically. -- David Roundy http://civet.berkeley.edu/droundy/

hi, nice post. David Roundy wrote:
... btw, in my experience, I've found that a useful metric for how "functionally" I am thinking is the frequency with which I use map, foldl and friends. At first they seemed really confusing (and I still get couldn't tell you the difference between foldl and foldr without looking it up), but when you get used to them they can cut the quantity of code you need to write dramatically.
maybe this will help with the foldl/foldr confusion: foldl (-) 0 [1,2,3,4] = (((0 - 1) - 2) - 3) - 4 foldr (-) 0 [1,2,3,4] = 1 - (2 - (3 - (4 - 0))) foldl groups things to the left, while foldr groups them to the right. hope this helped bye iavor -- ================================================== | Iavor S. Diatchki, Ph.D. student | | Department of Computer Science and Engineering | | School of OGI at OHSU | | http://www.cse.ogi.edu/~diatchki | ==================================================

Dear Haskellers! Another letter from newbie :) May you criticize my code for replacing substring in a string cited below? Any critics and comments are highly appreciated. And some more questions: 1. Is there more functional way for text processing? For example, intuitively I feel that there is more functional approach for matching than one suggested below. 2. Is there a kind of book simlar to "Text processing with Python?". 3. I found several regular exprssions library for Haskell. Which one would you recommend for *learning*---I am not too interested in performance by now, but rather in exampels of good Haskell. 4. What Haskell sources (snippets, modules, etc) can you recommend as examples of good Haskell. Replace: data Match = None | Rest String deriving Show match :: String -> String -> Match match pattern s = case match_ pattern s of ("", rest) -> Rest rest _ -> None where match_ :: String -> String -> (String, String) match_ pattern@(p:ps) str@(s:ss) = if p == s then match_ ps ss else (pattern, str) match_ pattern s = (pattern, s) findAll :: String ->String -> (String -> String) -> String findAll pattern = findAll_ where findAll_ :: String -> (String -> String) -> String findAll_ "" _ = "" findAll_ s@(head:tail) f = case match pattern s of Rest rest -> (f pattern) ++ findAll_ rest f None -> head:findAll_ tail f replace :: String -> String -> String -> String replace _ "" _ = "" replace what s to = case match what s of Rest rest -> to ++ replace what rest to None -> (head s):(replace what (tail s) to) replace3 what s to = findAll what s (\_ -> to) Notes: It seems that Match may be better written with Maybe. is there any pros & contros? Which version of replace would you prefer and why? Is it effecient enough or there are better ways? I beg your pardon for such a long letter. -- Best regards, antonmuhin mailto:antonmuhin@rambler.ru

On Tue, Feb 11, 2003 at 08:17:49PM +0300, antonmuhin ???? rambler.ru wrote:
Dear Haskellers!
Another letter from newbie :)
May you criticize my code for replacing substring in a string cited below? Any critics and comments are highly appreciated.
And some more questions:
1. Is there more functional way for text processing? For example, intuitively I feel that there is more functional approach for matching than one suggested below.type Match = String -> Maybe String
I think the following would be an example of a reasonably nice functional way of defining part of a regexp matching code. I think it would be relatively straightforward to extend it as much as you like. match here is the same as your match, and your replace old new s would be my replace (match old) new s. Looking back at what I've written, I'm thinking that perhaps the "Match" type should be a monad, since it seems to have monadic properties, and that might cut down on the amount of coding. Most notably, I bet the matchSequence function would just be the sequence function of a monad... type Match = String -> Maybe String -- replace replaces a matched regexp with a constant string. replace :: Match -> String -> String -> String replace m repl (c:cs) = case m (c:cs) of Nothing -> c : replace m repl cs Just r -> repl ++ replace m repl r replace _ _ "" = "" -- in a regexp a (i.e. the char a) matchchar :: Char -> Match matchchar m (c:cs) = if m == c then Just cs else Nothing -- in a regexp exp1exp2exp3 (i.e. in sequence) matchSequence :: [Match] -> Match matchSequence (m:ms) s = m s >>= matchSequence ms matchSequence [] s = Just s -- in a regexp abcd match :: String -> Match match s = matchSequence $ map matchchar s -- in a regexp (exp)* matchStar :: Match -> Match matchStar m s = case m s of Nothing -> Just s Just s' -> matchStar m s' -- in a regexp (exp)+ matchPlus :: Match -> Match matchPlus m s = case m s of Nothing -> Nothing Just s' -> matchStar m s' -- in a regexp (exp1|exp2|exp3) matchOr :: [Match] -> Match matchOr (m:ms) s = case m s of Nothing -> matchOr ms s Just s' -> Just s' matchOr [] s = Nothing -- In a regexp something like [abc] matchBrackets :: String -> Match matchBrackets s = matchOr $ map matchchar s -- David Roundy http://civet.berkeley.edu/droundy/
participants (5)
-
antonmuhin на rambler.ru
-
David Roundy
-
Ferenc Wagner
-
Iavor S. Diatchki
-
JJ