5 ms·
Let 5 = 6
- Periodic 17y agoThis is one of the things I like about Haskell. Operators like (-) are just like any other function, so you're free to redefine them for new input. If you want to define a world where 3 - 4 =5, you're free to do so. It makes it easy to explore some more complicated mathematical constructs.
- fserb 17y agoDo you care to elaborate on how '3-4=5' allows one to explore some more complicated mathematical constructs? Unless 'complicated' means 'ilogical' I cannot understand it. I think Haskell is a very nice language and it's flexibility on definitions is very cool, but I don't think this is a good example of it.
- bdr 17y ago3-4=5 in Z6, the modulo group with six elements. See http://en.wikipedia.org/wiki/Modular_arithmetic http://en.wikipedia.org/wiki/Modular_arithmetic
- fserb 17y agoBut you would never define it like this in Haskell... You'd probably do something like: let n - m = ( n + (-m) ) `mod` 6 'let 3 - 4 = 5' is just a non-sense example.
- ionfish 17y agoFor much the same reason, one would probably never want to write "let 1 = 1", but it's still a valid statement. It may not be interesting, but it's not nonsense.
- tedunangst 17y agoWhy is "3 - 4 = 5" in Haskell cool, but "x + y" in C++ is "OMG, it doesn't make any sense. + could do anything!"?
- mquander 17y agoRealistically? Because if you're programming in Haskell, you're probably programming by yourself or with a few other smart people, so either you understand the idioms you encounter or at least you can trust them to be applied in a consistent and effective manner. C++ is used more often as a common-denominator language for many programmers of varying skill who are collaborating on a project, and as you move toward that domain, transparency and safety start to become more important than power, since a big element of getting anything done is just not screwing each other over with unreadable code.
- eru 17y agoAnd you can define new operators in Haskell. So you can actually go out ouf your way and do not overload the existing ones.
- deleted 17y ago[deleted]
- JulianMorrison 17y agoAnd type classes force you to override related operators together. (With dependent types that Haskell doesn't have, the relationships between them could even be forced to adhere to mathematical axioms.)
- eru 17y ago> And type classes force you to override related operators together. You can get away with only implementing some of the functions in a typeclass. However you'll get a warning.
- mscarborough 17y ago
- Hoff 17y agoThis title reminds me of an ancient Fortran compiler bug; a case where a programmer could alter the value of a numeric constant within the Fortran code.
- megaduck 17y agoThis would make my proofs so much easier.
- monos 17y agoi dont know much haskell, but "variable assignment" is not the first thing that comes to mind if i think of functional programming.