> is it possible to convert IO Bool to Bool?
No. The reason for introducing the IO type is to preserve the purity of
Haskell, i.e., to ensure that expression evaluation doesn't depend on the
state of the outside world and doesn't alter this state.*) Allowing a
conversion from IO t to t would nullify this.
As you might have noticed, there was (or still is) a discussion about "yet
another monad tutorial" on The Haskell Cafe. Some of the messenges and, above
all, the monad tutorial itself may help you understand how I/O in Haskell
works. There is not a quick answer to your question like: "This way you
convert an IO Bool to a Bool." You will have to do some reading to understand
the basic ideas of I/O in Haskell. They are quiet different from what you
might know from other programming languages.
Wolfgang
*) This is at least how I would formulate it, others would probably phrase it
a bit different. ;-)
P.S.: Would you mind to configure your mail client such that your mails also
contain a plain text variant of your message?
_______________________________________________
Haskell-Cafe mailing list
Haskel...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
It makes no sense to convert an IO Bool to a Bool. If something
has type IO Bool that means it is an action which will get a
Bool from the outside world. It cannot be converted into a Bool.
If you want to use the action to get a Bool from the outside world
you should invoke the action in somewhere in the IO part of your code,
like this..
do ...
boolVal <- ioBoolAction
...
Regards
--
Adrian Hey
No, it's not... and for good reason! See the discussion at
http://www.haskell.org/hawiki/ThatAnnoyingIoType
and
http://www.haskell.org/hawiki/UsingIo
In general, the HaWiki has answers to lots of "newbie" questions like
this - you might find it useful to peruse (although you should
certainly continue to ask questions here too - we're a pretty friendly
bunch!).
Best wishes,
--KW 8-)
--
Keith Wansbrough <kw...@cl.cam.ac.uk>
http://www.cl.cam.ac.uk/users/kw217/
University of Cambridge Computer Laboratory.
Sure. Which Bool do you want? True?
> toTrue :: IO Bool -> Bool
> toTrue x = True
Or False?
> toFalse :: IO Bool -> Bool
> toFalse x = False
Maybe that's not what you had in mind.
I wouldn't call these *conversion* functions because they don't look at their
argument.
> Maybe that's not what you had in mind.
Surely not.
Wolfgang
On Thu, 14 Aug 2003, Wolfgang Jeltsch wrote:
> On Thursday, 2003-08-14, 17:05, CEST, Kevin S. Millikin wrote:
> > On Wednesday, August 13, 2003 11:20 PM, Tn X-10n
> > [SMTP:kawai...@hotmail.com] wrote:
> > > is it possible to convert IO Bool to Bool?
> >
> > Sure. Which Bool do you want? True?
> >
> > > toTrue :: IO Bool -> Bool
> > > toTrue x = True
> >
> > Or False?
> >
> > > toFalse :: IO Bool -> Bool
> > > toFalse x = False
There's also
boolFromIO :: IO Bool -> Bool
boolFromIO = boolFromIO
if you want to be even less useful :)
> I wouldn't call these *conversion* functions because they don't look at their
> argument.
>
> > Maybe that's not what you had in mind.
>
> Surely not.
>
> Wolfgang
I'm surprise nobody has mentioned unsafePerformIO (:: IO a -> a).
As the name suggests, it isn't referentially transparent.
Are you sure you need a function of type IO Bool -> Bool? What are you
trying to do?
Brandon
On Thu, Aug 14, 2003 at 11:30:11AM -0700, Brandon Michael Moore wrote:
> I'm surprise nobody has mentioned unsafePerformIO (:: IO a -> a).
> As the name suggests, it isn't referentially transparent.
I'm not surprised. First, it's not standard Haskell. Second, people
tend not to mention it because you really shouldn't use it unless
you know what you're doing.
Cheers,
Andrew Bromage
> hai guysis it possible to convert IO Bool to Bool?
Read the Gentle Introduction.
http://www.haskell.org/tutorial/