Hacker News new | past | comments | ask | show | jobs | submit login

F# is very un-functional in many ways. Immutable variables are the default but mutable variables are made with just the "mutable" keyword. There are also lots of imperative control structures, like while, and for. Those two combined means that imperative algorithims typically have two distinct translations into F#.

First you can translate it literally, where F# looks like a slightly more verbose version of Python. Second you can exploit all the functional features of F#, and using immutable variables, recursion and pattern matching.

F# also has extensive support for OOP, and uses it where OCaml-ers might use modules or functors.

In that way, F# can be a sort-of stepping stone between the imperative, OOP C# to more functional features of F#.




Un-functional might be a bit misleading for an ML-based, default immutable language. Impure might be slightly more accurate.

Having seen F# written by C# coders who've just learnt the syntax, and haskell programmers who are having to work in a .net environment, I'd say F# does a fairly good job of supporting both. It does make some trade offs to allow easy interop with the rest of the .net world (it's type system is much less powerful than Haskell, Scala or (especially) Idris) but depending on your environment that can be out weighed by the massive scale of the .net ecosystem, easy interop with your existing .net code and very, very good tooling.


Yeah, perhaps unfunctional wasn't the best word I could use. Either way, I'm a huge fan of F# and I think it's imperativeness is all-in-all a very good thing for adoption of the language.


The idea is that it is a functional first programming language, but allows you to use imperative or OO styles when the problem suits it.


The OOP and imperative capabilities also make it easier for people coming from this kind of programming style to learn F#, such as myself.

At first you write imperative F# to get used to the language and it's lack of verbose signs such as (, ; etc and hopefully you will be able to write more idiomatic/functional F# as your skill improves.


I'm not sure I'd say un-functional, just multiparadigm. But having at least some support for imperative programming is the norm in functional languages - ML does it, most LISP dialects do it, etc. Even Scheme, originally notable for its lack of loops, still has set! and idioms for combining it with closures and tail recursion to produce constructs that behave like loops.

And impure, of course. It's definitely an impure language. Personally, though, I'm not at all fond of conflating the terms "pure" and "functional". It's a terrible retcon that has more to do with the Haskell proselytism than with the development and history of functional programming or how its community has self-identified over the years. Note that the seminal book's title is "Purely Functional Data Structures", not something that's only three words long.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: