[Haskell-cafe] Bool as type class to serve EDSLs.
Henning Thielemann
lemming at henning-thielemann.de
Wed Jun 3 12:14:14 EDT 2009
Claus Reinke wrote:
>>> Do you argue that overloading logical operations like this in Haskell
>>> sacrifices type safety? Could programs "go wrong" [1] that use such
>>> abstractions?
>>
>> If I understand your point correctly, you are suggesting that such
>> programs
>> are still type safe. I agree with the claim that such features are
>> detrimental in practice though. Instead of lumping it with type safety,
>> then what do we call it? I think I've heard of languages that do such
>> conversions as "weakly" typed. Really the issue is with implicit
>> conversions, right?
>
> Isn't it merely a matter of balance?
You are completely right. I have to rephrase: The concrete example of
interpreting lists as booleans leads to too weak typing for my taste.
Let me give Python as an example: It has no static check whether a
sub-routine contains a 'return' statement. If it calls 'return', you
might call it a function, if it does not call 'return', you might call
it a procedure. Whether 'return' is called may vary at run-time, thus a
sub-routine can be both function and procedure. However, if the
sub-routine does not call 'return' it implicitly calls 'return None'
when leaving the scope of the sub-routine. 'None' is a value of every
type, just like bottom in Haskell. But in contrast to Haskell 'None' is
a well-defined value. As far as I remember, it is considered 'false' in
logical expressions. (PHP is even more extreme in interpreting all kinds
of values as booleans.) Now, whenever you forget to call 'return' the
resulting 'None' goes unnoticed through your program until at a very
unrelated place an error like "you tried to access the 5-th element of
the list None, which does not exist" pops up.
Sure we can implement this behaviour in Haskell, too, e.g. using the
Maybe type - but should we do it? I prefer an interpreter which refuses
to start the program with the message: 'you forgot a return'.
--
Mit freundlichen Gruessen
Henning Thielemann
Viele Gruesse
Henning
Martin-Luther-Universitaet Halle-Wittenberg, Institut fuer Informatik
Tel. +49 - 345 - 55 24773
Fax +49 - 345 - 55 27333
More information about the Haskell-Cafe
mailing list