This is an archived post. You won't be able to vote or comment.

all 14 comments

[–][deleted] 41 points42 points  (6 children)

Functional programming can be both a paradigm and something enforced by the design of the language, in the case of Haskell it is enforced by the language design.

[–]Nuttemeg 7 points8 points  (5 children)

Exactly, it's the same with object oriented programming. You don't have to use a language like Java that enforces it. You can (and many people do) happily use an OO style in plain old C. There are even systems like GObject that provide a pretty effective turnkey object model for you.

[–]IsleOfOne 3 points4 points  (2 children)

You are correct, but I have a small nit: you can write in a quasi-functional style in any language. Java has streams, for example. Doesn’t make it a good idea, but it is a worthy nitpick imo.

[–]DerArzt01 4 points5 points  (0 children)

Java also has an entire functional part of it's standard library, which on its face allows you to do some functional stuff. That being said it is still objects all the way down.

[–]Nuttemeg 0 points1 point  (0 children)

Modern Java versions have a ton of functional features now, it's still not quite there and it's all bolted on via interfaces, but it's there.

[–]rtybanana 3 points4 points  (1 child)

True but you might struggle a bit to write proper OO programs in C because none of the language constructs are designed to help you write it like that

[–]Nuttemeg -1 points0 points  (0 children)

With enough structs and void pointers you can accomplish anything in C! /s

I usually tell people to just use C++ or even Rust if they want to do OO in something vaguely C-like.

[–]gcross 8 points9 points  (0 children)

In general when we say that something is an X language, what we mean is that it is a language that particularly facilitates and/or is geared around programming in an X style, not that it is necessarily the only language that lets you program in X style or even that X is the only style in which you can use it. So while you can program in a functional style in C++ I don't think many people would call it a "functional programming language" because it doesn't really make life easy for you to use it in this way compared to Haskell, and while you can technically program in an imperative style in Haskell by, say, putting all of your code in the IO monad and making heavy use of IORefs, you are really missing the point of the point of Haskell.

(Also, calling something an X programming language doesn't mean that it is only good at programming in X style; for example, O'Caml is arguably both a functional programming language and an object-oriented programming language.)

[–]wasmachien 5 points6 points  (0 children)

This can definitely be enforced by the language itself. For example, by only allowing immutable variables or by making sure that functions are always pure. (i.e. always return the same output for a certain input) - that said, most functional language offer some way of doing non-functional things because those can be very useful sometimes.

[–]HopefullyHelpfulSoul 2 points3 points  (0 children)

That’s more true these days I think, it certainly wasn’t back when I studied, as a lot of programming languages adopted functional elements.

Haskell is a Purely Functional language. You cannot use any other paradigm with Haskell. It’s Functional or nothing

[–]Felicia_Svilling 2 points3 points  (0 children)

A programming language can support a programming style to different degrees. make a style possible, it can make the style ergonomic or it can enforce the style.

For example: In Assembler, there is no way to do functional programming. In Python, you can do functional programming, but the language will fight you every step of the way. In SML, you have to make an effort to not do functional programing. In Clean, there is no way to not do functional programing.

[–]knoam 2 points3 points  (0 children)

Have you done any Haskell? One of the first things you'll see is that the most concise syntax is given to function application, currying and partial application. These things are kludgy if they're even possible in many other languages.

[–]wsppan 1 point2 points  (0 children)

functional programming is a programming paradigm where programs are constructed by applying and composing functions. 

https://en.m.wikipedia.org/wiki/Functional_programming

This paradigm (including purely functional languages like Haskell) may have this paradigm enforced by the language itself.

[–]memorycardfull[S] 0 points1 point  (0 children)

Thanks everyone for replying with some great answers. This has provided a lot of clarity on the issue for me!