
If you are running from GHCi, just type run 100 at the prompt.. If you intend to compile it, you have to add main = print $ run 100 The compiler adds a call to main::IO (), which is intended to be the main entry point of your code. We need to add print, as run has type run::Int->[Door] so run 100 has type [Door]. print is print::(Show a) => a -> IO () The IO () stands for an empty IO monad, which is the black magic of haskell, intended to separate pure code from I/O side-effects... On Mon, May 3, 2010 at 06:31, Samuel Williams < space.ship.traveller@gmail.com> wrote:
Also, one more thing - if someone could write some comments to go along with the source code that explain what it is doing, that would be really helpful. I can see the general structure, but I don't know the ins and outs of Haskell. If someone could augment the example with comments explaining what the functions do that would be great!
data *Door* = *Open* | *Closed* deriving *Show*
toggle *Open* = *Closed* toggle *Closed* = *Open*
pass k = zipWith ($) (cycle $ replicate k *id* ++ [toggle])
run n = foldl (flip pass) (replicate n *Closed*) [0..n]
Do I need to add run 100 to the end of the example for it to actually do something?
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Rafael Gustavo da Cunha Pereira Pinto