Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: In need of a sequence iterator. (Haskell)

by kelan (Deacon)
on Aug 08, 2005 at 20:38 UTC ( #482019=note: print w/replies, xml ) Need Help??


in reply to In need of a sequence iterator.

I solved this question on my own in Haskell at the time it was posted. It involved using a couple nested maps and some other things that were quite complicated to get my head around (as I remember). However, recently I've been experimenting with using lists as monads, and found my solution to this puzzle. Reworking it from that point of view, it becomes nice and clear. I know you're dabbling with Haskell, so I thought you might be interested.

import Char -- for intToDigit gen :: Int -> Int -> [String] gen 0 _ = [] gen len max = do d <- map intToDigit [0 .. max-1] ds <- [] : gen (len-1) max return (d:ds)

Below is the first version I came up with. You might not want to read it. It's rather ungainly.

gen :: Int -> Int -> [String] gen 0 _ = [] gen len max = concat ( map ( \digit -> [digit] : ( map ( digit : ) ( gen (len - 1) max ) ) ) ( map intToDigit [0 .. max-1] ) )

Replies are listed 'Best First'.
Re^2: In need of a sequence iterator. (Haskell)
by BrowserUk (Patriarch) on Aug 09, 2005 at 22:10 UTC

    I've pretty much given up on Haskell. It's fine if all you want to do is prove that your new variation of Fibonacci compiles okay, but if you want to actually see the output, forget it. Much less if you want to read your data from an external source.


    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://482019]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2022-08-17 17:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?