While loop in Haskell with a condition -


i'm having little haskell situation on here. i'm trying write 2 functions monads. first 1 supposed iterate through function long condition true input / output of function. second 1 supposed use first 1 take number input , write output until enter space.

i'm stuck this, help?

module test  while :: (a -> bool) -> (a -> io a) -> -> io while praed funktion x =                          f <- praed (funktion x)                          if f == true                                              y <- funktion x                                              while praed funktion y                          else return x    power2 :: io () power2 = putstr (please enter number.")             <- getchar             while praed funktion             praed x = if x /= ' ' false else true                   funktion = 

import control.monad  while :: (a -> bool) -> (a -> io a) -> -> io while praed funktion x     | praed x   =         y <- funktion x         while praed funktion y     | otherwise = return x   power2 :: io () power2 =     putstr "please enter number."     <- getchar     let praed x = x /= ' '     let f x =         putchar x         getchar     while praed f '?'     return () 

some notes:

  • using if x true else false redundant, it's equivalent x.
  • similarly if x == true ... redundant , equivalent if x ....
  • you need distinguish between io actions , results. example, if yo do

    do     <- getchar     ... 

    then in ... i represents result of action, character, i :: char. getchar :: io char action itself. can view recipe returns char when performed. can pass recipe around functions etc., , performed when executed somewhere.

  • your while called funktion twice, isn't intend - read character twice, check first 1 , return second one. remember, funktion action, each time "invoke" action (for example using <- funktion ... in do notation), action run again. should rather like

    do     y <- funktion x     f <- praed y     -- ... 

    (my code different, checks argument passed it.)


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -