9 ms·
The designers of Haskell (and Haskell is one of the few successful design-by-committee languages,) were not doing things "your way" (where I assume you are a wo
by adimitrov 13y ago
The designers of Haskell (and Haskell is one of the few successful design-by-committee languages,) were not doing things "your way" (where I assume you are a working programmer, with knowledge of some or even many traditional imperative languages.)
They were PL researchers. Used to ML, Common Lisp, Ada, and, most importantly, Mathematics and Category and Type Theory.
`data` introduces an algebraic data type, so it makes sense to use data as a keyword. `type` and `newtype`, on the other hand, are programmer's conveniences: both carry no runtime cost, they are not actually part of the semantics of the backend language.
`map` is a function that's really just a specialization of `fmap`. Now, my category theory is a bit weak, but if I'm thinking correctly here, `fmap f` is an endofunctor in the category of functors, and so it makes perfect sense to call "mappable" Functor. There's also "Traversable," which works pretty much like a fully-fledged "mappable" with all extras, but also requires a Functor instance.
Keywords, and idiosyncrasies of a syntactic nature are really just superficial. The actual elegance of the language is its type system. (The actual warts of the language are, for the most part, also in the type system; records for example.) The latter criticism about `mappable` is really just due to the fact that you haven't gotten used to the underlying theory (and I don't blame you, it's hard.) But getting used to it can be rewarding. I'm not saying it's going to make you a better programmer (I'm not necessarily of that opinion,) but it's rewarding in its own right.
Oh, and the difference between data constructors, type names, and, later, kind names (with promotion, since 7.4,) can be confusing. I sometimes find it an oversight that they are not distinguished syntactically, I think that would greatly help most newbies, and sometimes even make things easier to read and understand for veterans, too.
- rhizome31 13y ago+1 for your thoughtful reply. I've tinkered with other functional languages (Erlang, Scheme and Clojure), but Haskell is a stranger beast.
- tel 13y agoScheme, Clojure, and most of Erlang are on an entirely different side of a fairly large chasm within the lay term "functional programming". Haskell, ML, Ada, Coq, and even some parts of Scala are just entirely different beasts. The underlying math is far more pronounced, leadi to new terminology and power.
- klibertp 13y agoAda?! It's purely imperative, type-safe language, no? At least that was the impression I got when it was forced on me at university. Also, ML? I know OCaml a bit, but according to this comparison: http://adam.chlipala.net/mlcomp/ http://adam.chlipala.net/mlcomp/ Standard ML has a "ref" type, which in effect allows mutable state. While it lack a bit of a syntactic sugar for this, OCaml's mutable record fields are implemented in terms of refs, so in the end SML isn't "more functional" in this than OCaml. Also, according to this answer (didn't check specs) SML has at least a WHILE loop: http://stackoverflow.com/questions/818324/loops-in-sml-nj http://stackoverflow.com/questions/818324/loops-in-sml-nj which is typical to imperative languages. OCaml makes no attempt to outlaw side-effect (I suppose SML is similar), it allows them explicitly by introducing functions which return () (unit type), which are called purely for their side-effects. There is even List.iter function, which accepts a function executed for each element only for side-effects. And side-effects are not restricted in any way. On the other hand Erlang has nothing like that - no loops, no mutable state in the language and it's side-effects are restricted to message passing. While Scheme and Clojure, too, allow mutable state and non-pure functions, the default is immutable and pure for almost everything. In Racket the most used data-structure, a pair (and lists by extensions) is immutable by default and all the functions working on pairs and lists are pure. There is another type, "mutable pair", which is used to construct mutable lists, but I haven't seen it used yet. Coq is not even turing complete. Anyway, I much prefer talking about "functional style" than "functional programming"/"functional languages". If you think that one cannot use monads outside of Haskell - you're wrong. The same applies for lazy evaluation, which is available in many languages as extension or special syntactic construct in the language itself. EDIT: I realized that parent probably thought of AGDA instead of ADA. And so I just installed it to check it out :)
- jmilkbal 13y agoI use Ada (a proper noun) regularly. It is not a functional language, but encourages a lot of the same things that functional people like to talk about. Ada is a wonderful language to use. It's rather boring and uneventful and is not accompanied by buzz words, but most of the Ada folks I know (converts or otherwise) all suggest that they're accomplishing more in less time with fewer bugs than they get with other languages. A lot of the new, buzzy languages seem to be solving problems that Ada took care of in the 80s and 90s. It's definitely worth a look if only to improve your approaches to software. Edited for fun and grammar!
- ccdan 13y agoHuge mistake on their part, typical of math people. High level programming languages have to be as close as possible to human languages (English) not to some obscure mathematical concepts and notation that most people don't care about. Actually math notation itself (cryptic, inconsistent, ambiguous) is a horrible result of math people's communication handicap and ineptitude.
- pizza 13y ago> High level programming languages have to be as close as possible to human languages (English) not to some obscure mathematical concepts and notation that most people don't care about. Haskell wasn't created for "most people". It's not some replacement for Python or Ruby, it was designed for formality.
- ccdan 13y agoI don't know who it was created for, but I know lots of FP advocates (Haskellers included) whining that FP languages aren't used (almost at all) in the software industry.
- pandaman 13y agoThis depends on the point of view. I expect to find a rather high standards in Haskell programs than, say, Ruby, for exactly the same reasons you've mentioned and I think it's an awesome feature, quite the opposite to a mistake. And yes, I am a "real programmer" and don't use Haskell at work myself (for the run-time performance reasons).
- nbouscal 13y agoNo. The math notation that is used across all branches of mathematics is consistent and unambiguous (the notation of formal logic, naive set theory, etc). The only ambiguity typically comes from traversing different branches of the discipline, which is inevitable considering how many branches there are and how deep they go. Furthermore, mathematics is all about communication. The language of mathematics exists to codify concepts so that they can be talked about concisely. Being able to say 'group' instead of 'set with an associative binary operation with identities' is essential if you want to be able to build on top of that concept without taking an hour to read one theorem. The handicap in communication isn't on the mathematics end, it's on your end. You seem to expect them to be able to explain structures to you that took years of work to build by using the same language that you use to talk about sports or social events. The reality is that you are not the target audience of their communication, and they are okay with that. You should be too. The weirdest assertion that you made is that high-level programming languages ought to be as close as possible to human languages. The two categories of languages exist to communicate fundamentally and widely different groups of concepts. Words represent categories of analogous concepts, and the relevant categories in human life are nothing like the relevant categories in programming. In Haskell, 'functor', 'applicative functor', and 'monad' are highly relevant categories. They pop up everywhere and can be leveraged with great benefit. In human life these concepts are far less common, and thus do not merit words in the common vernacular. Were we to use a programming language modeled on English, we would miss the benefit of these abstractions, trading them for categories like 'dog' and 'car' which have very little practical use in typical programming.