4 ms·
It would be nice if Haskell could figure out (-) functions; as it is, it always consider things like (- 2) to be a number, not a function (even when only a func
by gizmo686 10y ago
It would be nice if Haskell could figure out (-) functions; as it is, it always consider things like (- 2) to be a number, not a function (even when only a function would typecheck).
- prodigal_erik 10y agoML might have had the right idea, using op~ for unary negation and op- for binary subtraction. I definitely would not want parsing to depend on type declarations; that's a slippery slope towards Perl...
- gizmo686 10y agoI suspect that you could do this already using typeclasses. We want (-2) to be a function of the type `Num a => a -> a`, so we could, in theory, make functions of this type an instance of Num. I do not immediately see this causing problems for correct programs, but it would probably lead to horribly confusing problems in incorrect code, including converting some type errors into runtime errors. A simpler approach is to say that you can not have a space after the unary "-", so (-2) parses to a numeric literal, and (- 2) parses to a function.