Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Haskell, is there infinity :: Num a => a?

I'm trying to implement a data structure where if I had the use of infinity for numerical comparison purposes, it would simply things greatly. Note this isn't maxBound/minBound, because a value can be <= maxbound, but all values would be < infinity.

No hope?

like image 473
me2 Avatar asked Mar 01 '10 09:03

me2


2 Answers

Well how about that! It turns out if you just type 1/0 it returns Infinity! On ghci:

Prelude> 1/0 Infinity Prelude> :t 1/0 1/0 :: (Fractional t) => t Prelude> let inf=1/0 Prelude> filter (>=inf) [1..] 

and then of course it runs forever, never finding a number bigger than infinity. (But see ephemient's comments below on the actual behavior of [1..])

like image 54
Tyler Avatar answered Oct 21 '22 06:10

Tyler


infinity = read "Infinity" 
like image 20
newacct Avatar answered Oct 21 '22 08:10

newacct