Some days ago I had an idea, which I don't know if it's worth exploring, so 
I'll just share it here and ask for some feedback.

Thinking about how to handle only valid state of an application, I tought 
it would be nice if, for every function, we could be able to specify 
precisely its domain, instead of dealing with unacceptable input values 
with special return values (i.e. what we usually do with Option).

Think for example about the `logBase` function in the `Core.Basics` 
package. Its type annotation is `logBase: Float -> Float -> Float`, where 
the first Float is the base of the logarithm and the second is the 
argument. Actually, a logarithm is defined only for a base positive and not 
equal to one and for a positive argument.

At the moment the presence of invalid input values is handled returning 
`Infinity` or `NaN` when the logarithm is actually not defined.

Wouldn't it be nicer if we could define the same function as something like

logBase: (Float | > 0 && != 1) -> (Float | > 0) -> Float

in a way that the compiler itself could check that we are invoking the 
function only with correct values to avoid NaN return values?

As I said, I don't know if this is a good idea, and I don't know how much 
of a burder this would be to the compiler... 

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to