[Haskell-cafe] Set of reals...?

Glynn Clements glynn at gclements.plus.com
Fri Oct 29 23:07:36 EDT 2004


> >Double already has +Inf and -Inf; it's just that Haskell doesn't have
> >(AFAIK) syntax to write them as constants.
> 	In the source for the GHC libraries it uses 1/0 for +Infinity
> and -1/0 for -Infinity, so I assume these are the "official" way to do it.
> Personally I would define nicer names:
> 	positiveInfinity :: Double
> 	positiveInfinity = 1/0
> 	negativeInfinity :: Double
> 	negativeInfinity = -1/0

Or just:

	infinity = 1/0

and use -infinity for the negative.

One other nit: isn't the read/show syntax for Haskell98 types supposed
to valid Haskell syntax?

>From http://www.haskell.org/onlinereport/derived.html#derived-text

	The result of show is a syntactically correct Haskell
	expression containing only constants, given the fixity
	declarations in force at the point where the type is declared.

[Note: the above sentecne refers specifically to derived instances,
but induction would require that it also holds for base types.]


	Prelude> let infinity = 1/0 :: Double
	Prelude> show infinity
	Prelude> read (show infinity) :: Double
	Prelude> Infinity
	<interactive>:1: Data constructor not in scope: `Infinity'

Glynn Clements <glynn at gclements.plus.com>

More information about the Haskell-Cafe mailing list