[Haskell-cafe] Show function a -> String
Ketil Malde
ketil at malde.org
Fri Nov 27 10:36:14 EST 2009
Tsunkiet Man <temp.tsun at gmail.com> writes:
Context:
someFunction :: Integer -> String
someFunction = show
> However it asks me how my function can fail? Well I know my function fails
> by definition when I do not insert an Integer into SomeFunction. Like
> SomeFunction 2.3425221
The compiler guarantees that this will not happen, thus your function
will not get the opportunity to fail.
> and now I also know that when I insert a number that
> is very close to zero (I think a denormalized value means that a value is
> very close to zero:
The numbers closest to zero that you are able to pass, are 1 and -1.
Both of which should work, no?
> Now I also know that when I use 'undefined' I would get an error.
I'd argue that it's not your function that fails, but the parameter
(whose evaluation causes an exception).
> So what other cases are there?
Well, it might fail to terminate (loop forever). Semantically, I think
this is treated as _|_ just like passing it 'undefined'. I think you'll
have a hard time doing this with 'show', though.
> (I asked my question about Floating
> because I guessed it would be similiar to Integers)
Floating point (IEEE 754) has its own set of problems, but in general, I
think 'show' is fairly robust. But perhaps you can you think of a
resource it can run out of?
-k
--
If I haven't seen further, it is by standing in the footprints of giants
More information about the Haskell-Cafe
mailing list