6 ms·
I think the Haskell, OCaml, F# people are promoting their language of choice the wrong way. The way to do it would be to show concrete examples of problems whic
by galaxyLogic 12y ago
I think the Haskell, OCaml, F# people are promoting their language of choice the wrong way. The way to do it would be to show concrete examples of problems which are difficult to solve in say Java, and then show how that is a non-problem in Haskell etc.
Of course if you know your language very well, it is much easier for YOU to be working with it. Just saying it has this or that feature is great, but does not really tell us why it would be costly to do similar things in other languages.
What does FP really mean? The term is used frequently as a synonym for Haskell. Does it mean "type-inference"? But is that really a 'functional' feature? Does it mean 'immutability'? In Java you can declare your data to be immutable. Does it mean 'closures? Or being able to pass a function as an argument or result. You can do those in JavaScript.
- codygman 12y agoFor me, purity, functional composition, and avoiding mutable state.
- galaxyLogic 12y agoMakes sense, a function must always return the same value for the same argument. Therefore if there were mutable state you might have things that look like functions but are really not. But what is "purity"? Does it mean that you can NOT HAVE mutable state in any program written in a "purely functional" language? I still don't quite get it how a language could be "purely" functional if it has to do IO. Reading the user's input will return a different value most of the time. And what do you do in Haskel if you need to know the current TIME for any reason? It can't be returned by a "function" because its result will always be different. So there must be something ELSE besides functions in the language. But doesn't that then mean that it is no longer a "purely functional" lanaguage?
- mhogomchungu 12y agoA "pure" functional programming language has the problem you have identified and that is why haskel for a very long time was considered an academic language since it couldnt do anything useful as anything useful requires side effects like IO. The above is how haskel was introduced when i took it in CS at Syracuse University. The practicalities of haskel as a useful and practical language are realized through monads[1]. Use of monads to deal with side effects and impure world automatically make haskel "none pure". With the existence of monads,the purity of the language is a matter of opinion or degrees since it largely based on "idiomatic" usage. To say haskel is an impure language because of monads will be akin to say C# is an unsafe language because it allows pointer managements through the usage of "unsafe" keyword. [1] http://en.wikipedia.org/wiki/Monad_%28functional_programming%29 http://en.wikipedia.org/wiki/Monad_%28functional_programming...
- galaxyLogic 12y agoGood explanation, thanks. I would take from it that "purity" is relative, just as "safeness" is. There are no safe languages, nor pure ones, just some that are more pure than others. I guess I would have grasped your point earlier if Haskell had a keyword "IMPURE", just like C# has the keyword "unsafe". Come to think of it, doesn't "pure" in the context of PLs mean much the same as "safe"?
- skrebbel 12y agoThis is actually a very nice one: http://fr.slideshare.net/ScottWlaschin/ddd-with-fsharptypesystemlondonndc2013 http://fr.slideshare.net/ScottWlaschin/ddd-with-fsharptypesy... It shows how F# is a much more suitable language than C# for Domain-Driven Design (a popular design approach for boring database software which _originated_ in C#-o-world). It makes a very compelling case that you're just making life hard for yourself if you do domain modelling in C# instead of a functional language.
- grayrest 12y ago> The way to do it would be to show concrete examples of problems which are difficult to solve in say Java, and then show how that is a non-problem in Haskell etc. I've been impressed by the Mirage blog posts [1]. If I were going to pick a single example with the biggest size/complexity win over an imperative language, the ASN.1 Combinators [2] post would be the example. [1] http://openmirage.org/blog/announcing-mirage-20-release http://openmirage.org/blog/announcing-mirage-20-release [2] http://openmirage.org/blog/introducing-asn1 http://openmirage.org/blog/introducing-asn1 The general problem with the good examples is that they're deeply tied into a different school of thought. If you don't have a general idea of what's going on, the example is completely incomprehensible. The only functional language advocacy site I know of that's really attempting to bridge this gap is "F# for fun and profit" [3]. [3] http://fsharpforfunandprofit.com/why-use-fsharp/ http://fsharpforfunandprofit.com/why-use-fsharp/
- Peaker 12y agoYou can write functional programs in Java, because it supports immutability, pure functions, etc. The fact Java has these features does not mean they are not FP :)
- tel 12y ago"Functional" is really poorly defined. Instead, here are some reasons to feel ML/Haskell are valuable ML and Haskell: ubiquitous use of higher order functions through standard library; concise syntax for lambdas; bi-directional type inference with principle typing; named algebraic data types including sums, products, exponentials, recursion, universal, and existential quantification; ubiquitous purity, generalization at higher-kinded types, ubiquitous immutability; effect typing. ML alone: true modules; module functors; structural equality in typing (polymorphic variants); great metaprogramming (camlp4) Haskell alone: bounded polymorphism (typeclasses), completely ubiquitous purity/completely ubiquitous effect typing; completely ubiquitous immutability; lazy evaluation; a standard library including many high-level higher-kinded type generalizations (functor, monad, applicative, traversable, foldable, category, arrow, anything else you can think up); ok metaprogramming (template haskell); programmer controlled rewrite rules, results in list fusion/vector fusion I list more under Haskell partly because I'm just more familiar with it, but also because it takes more things further and thus derives greater differentiation for it.