I'm newbie of Haskell. And I'm learning about monads.
data Container a = Container a deriving Show
x = Container 1 :: Container Int
plusOne :: Container Int -> Container Int
plusOne (Container x) = Container (x+1)
Is there any way to lift plusOne
to apply to Container (IO Int)
?
Or should I define a new function, such as:
plusOne' :: Container (IO Int) -> Container (IO Int)
plusOne' (Container x) = Container (liftM (+1) x)
Thanks all :-) And then Is there any way to avoid redefine plusOne ?
Because whan I build program, first I build program with non-monadic-type container(normal value such as: Container Int ..etc), And I test function with specified value (Container 10..).
And after that I try to apply these program to random or generated value. This is my basic approach for programming in other language (such as Lisp, Python..)
So I don't want to redefine function when I want to try to apply these function to monadic-value container.
this approach doesn't work on Haskell programming? Should I change my mind-model? Or I misunderstanding about Haskell?