A Haskell question

Status
Not open for further replies.
D

Deleted member 5324

Guest
Originally posted by GrimLock:
But if I type "iterate (\x -> (b * x + 1) `mod' m) a " at the Hugs prompt, it does seem to infinitely make a list (have to CTRL-C to terminate it). Are you saying that it shouldn't be doing that?

Well, imagine the prompt -- it probably wants to print lists. And to print that list, it has to take some elements...but it's never going to get to the end, because it's an infinite list!

Try instead binding that expression to a variable (if that's even possible -- I don't use Haskell, so I can't be sure :)) If you can bind it to a variable, it should return immediately. Then, for instance, try "take 10 variable" to see the first 10 elements.

Jeremy
 
Originally posted by GrimLock:
Ok I see what you're saying. And I don't think you can bind something to a variable since in Haskell there's no variable assignments (something thats weird getting used when all my life I've done imperative programming).

Notice he said bind, not assign. The distinction is important. Any functional language will allow you to bind variables. Not all allow variable assignments.

floccinau
 

GrimLock

Ars Tribunus Militum
2,189
Subscriptor
Notice he said bind, not assign. The distinction is important. Any functional language will allow you to bind variables. Not all allow variable assignments.

Sorry I didn't know about binding variables. I can see the distinction now. Anyways I was able to solve the problem as I edited before in an earlier post without binding.
 
Status
Not open for further replies.