Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IO Bool -> Bool

353 views
Skip to first unread message

Wolfgang Jeltsch

unread,
Aug 14, 2003, 3:44:32 AM8/14/03
to The Haskell Cafe
On Thursday, 2003-08-14, 07:20, CEST, Tn X-10n wrote:
> hai guys

> 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

Adrian Hey

unread,
Aug 14, 2003, 4:11:30 AM8/14/03
to Tn X-10n, haskel...@haskell.org
On Thursday 14 August 2003 06:20, Tn X-10n wrote:
> <html><div style='background-color:'><DIV>
> <P><BR>hai guys</P>is it possible to convert IO Bool to
> Bool?</DIV></div><br clear=all><hr>Get 10mb of e-mail space with <a
> href="http://g.msn.com/8HMTENSG/2737??PS=">MSN Hotmail Extra Storage</a> at
> only S$36 per year including GST</html>

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

Keith Wansbrough

unread,
Aug 14, 2003, 5:46:34 AM8/14/03
to Tn X-10n, haskel...@haskell.org
> <P><BR>hai guys</P>is it possible to convert IO Bool to Bool?

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.

Kevin S. Millikin

unread,
Aug 14, 2003, 11:07:36 AM8/14/03
to Tn X-10n, haskel...@haskell.org
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

Maybe that's not what you had in mind.

Wolfgang Jeltsch

unread,
Aug 14, 2003, 12:03:31 PM8/14/03
to The Haskell Cafe
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

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

Brandon Michael Moore

unread,
Aug 14, 2003, 2:31:31 PM8/14/03
to haskel...@haskell.org

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

Andrew J Bromage

unread,
Aug 15, 2003, 2:13:43 AM8/15/03
to Brandon Michael Moore, haskel...@haskell.org
G'day all.

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

Derek Elkins

unread,
Aug 15, 2003, 7:47:32 PM8/15/03
to Tn X-10n, haskel...@haskell.org
On Thu, 14 Aug 2003 13:20:05 +0800
"Tn X-10n" <kawai...@hotmail.com> wrote:

> hai guysis it possible to convert IO Bool to Bool?

Read the Gentle Introduction.

http://www.haskell.org/tutorial/

0 new messages