Convenient multi-paradigm programming in F#

59 views
Skip to first unread message

Feofilakt

unread,
Feb 7, 2017, 10:01:30 PM2/7/17
to F# Discussions
Hello! I'm thinking of studying F# because of its multi-paradigm, concise syntax and .NET integration, but I'm little confused by that people say despite F# is declared as a multi-paradigm language, attempts of mutable programming are full of pain, and only functional programming is convenient. Is that true?

Tomas Jansson

unread,
Feb 8, 2017, 1:27:19 AM2/8/17
to F# Discussions
I wouldn't say it is full of pain, but functional programming is easier since F# is a functional first language. The opposite is true for c#, you can do functional programming but there it is really a pain in the a**.

On Wed, 8 Feb 2017 at 04:01, Feofilakt <feofilaktf...@gmail.com> wrote:
Hello! I'm thinking of studying F# because of its multi-paradigm, concise syntax and .NET integration, but I'm little confused by that people say despite F# is declared as a multi-paradigm language, attempts of mutable programming are full of pain, and only functional programming is convenient. Is that true?

--
--
To post, send email to fsharp-o...@googlegroups.com
To unsubscribe, send email to
fsharp-opensou...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/fsharp-opensource
---
You received this message because you are subscribed to the Google Groups "F# Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fsharp-opensou...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Feofilakt

unread,
Feb 8, 2017, 2:48:50 AM2/8/17
to F# Discussions
No, I mean that F# intentionally obstructs imperative programming, for example, by less comfortable syntax, although it could nicely support both functional and imperative styles if not prejudices. Thats they say.

среда, 8 февраля 2017 г., 13:27:19 UTC+7 пользователь Tomas Jansson написал:

Tomas Jansson

unread,
Feb 8, 2017, 2:53:03 AM2/8/17
to F# Discussions
I don't think F# intentionally obstructs imperative programming, that is an effect of being functional first if you ask me.

Isaac Abraham

unread,
Feb 8, 2017, 3:18:35 AM2/8/17
to Feofilakt, F# Discussions
Maybe better to say that it intentionally makes it easy to write code in a functional style. You can do OO in it – indeed some parts of F# have better support for OO than C# - but in general it feels unnatural doing lots of OO in F#, in my experience.

From: Feofilakt
Sent: 08 February 2017 08:48
To: F# Discussions
Subject: Re: Convenient multi-paradigm programming in F#

No, I mean that F# intentionally obstructs imperative programming, for example, by less comfortable syntax, although it could nicely support both functional and imperative styles if not prejudices. Thats they say.среда, 8 февраля 2017 г., 13:27:19 UTC+7 пользователь Tomas Jansson написал:I wouldn't say it is full of pain, but functional programming is easier since F# is a functional first language. The opposite is true for c#, you can do functional programming but there it is really a pain in the a**. On Wed, 8 Feb 2017 at 04:01, Feofilakt feofilaktf...@gmail.com wrote:Hello! I'm thinking of studying F# because of its multi-paradigm, concise syntax and .NET integration, but I'm little confused by that people say despite F# is declared as a multi-paradigm language, attempts of mutable programming are full of pain, and only functional programming is convenient. Is that true?

Warren Young

unread,
Feb 8, 2017, 12:42:14 PM2/8/17
to fsharp-o...@googlegroups.com
On Feb 8, 2017, at 12:52 AM, Tomas Jansson <tomas....@gmail.com> wrote:
>
> I don't think F# intentionally obstructs imperative programming

I do:

1. Value-to-name binding uses one character (=) in F# whereas variable assignment uses two, one of which requires a Shift (<-).

2. “let” is immutable by default. To get a mutable variable instead of an immutable value, you must use “ref” or “mutable”.


There are similar costs for writing OO code instead of pure FP code, such as that

let notAMethod =
statement
statement
etc

gives you an immutable value, not a procedure (i.e. a value-less function) method as you may be expecting. To force evaluation of the expressions each time the method is called, and for other .NET code to see this as a method, you have to give () explicitly, which is a special value in F#, not just syntactic brackets:

member this.procedureTypeMethod() =
statement
statement
etc

Also note the need for “member this.” if you need the method to be available outside the class. Another cost for writing OO instead of FP code.


I believe these costs are a good thing. These language design decisions purposefully make the preferred path less costly to type.

If the OP is looking at these costs and then wondering why write in F# if he intends to write imperative and OO style code primarily, and dribble in bits of FP as he becomes comfortable with F#, I think that’s fine. His F# code will be a bit more verbose than it really must be, but probably still less verbose than the equivalent C# code.

Feofilakt

unread,
Feb 12, 2017, 9:33:04 PM2/12/17
to F# Discussions
It is possible to influence F# responsible persons for affecting F# be equally costs for both mutable and immutable paradigms?

четверг, 9 февраля 2017 г., 0:42:14 UTC+7 пользователь Warren Young написал:

Kevin Ransom

unread,
Feb 12, 2017, 10:29:08 PM2/12/17
to fsharp-o...@googlegroups.com

F#  is a functional first programming language.  It is intended to provide an excellent functional programming experience.  It is also a hybrid programming language being also an expressive programming language for OO programming.


The costs expressed earlier are by design.  It is intended that F# is immutable by default, gaining access to mutability requires additional keystrokes and thought.  To be fair, non-functional languages could also benefit from immutability by default.  Having a clear distinction between binding and mutating a value is very useful at code review time.  In short mutating a value in F# is always an indicator that close attention needs to be paid when reviewing the code.


Looping would be made simpler if there was break; continue and goto ... however ... those would really break the everything is an expression ... and usually if I find myself wanting to type those keywords ...  I know that I am thinking about the problem wrongly ... it usually occurs when I am transliterating C# code rather than rewriting it.

I think in truth there are many fine choices of language for programming OO style.  F# is aimed at being a First class Functional programming language with a strong set of features enabling OO style programming where it is necessary.

Anyway that is just my 2 cents ... and probably not even worth that much ...

Kevin


From: fsharp-o...@googlegroups.com <fsharp-o...@googlegroups.com> on behalf of Feofilakt <feofilaktf...@gmail.com>
Sent: Monday, February 13, 2017 2:33 AM

To: F# Discussions
Subject: Re: Convenient multi-paradigm programming in F#
--

Warren Young

unread,
Feb 13, 2017, 2:36:37 PM2/13/17
to fsharp-o...@googlegroups.com
On Feb 12, 2017, at 7:33 PM, Feofilakt <feofilaktf...@gmail.com> wrote:
>
> It is possible to influence F# responsible persons for affecting F#

Yes: https://github.com/fsharp/fslang-suggestions

> be equally costs for both mutable and immutable paradigms?

I can tell you right now that you’re not going to get any traction on that effort, for two major reasons:

1. The time to influence the “shape” of the language was back in the F# 1.0 and earlier days. The last major change in this area was in F# 1.1, when the lightweight syntax feature was added:

https://blogs.msdn.microsoft.com/dsyme/2006/08/23/lightweight-syntax-option-in-f-1-1-12-3/

That happened way back in 2006! Even if you argue that we shouldn’t count that until 2010 when the light syntax became the default, that’s still quite a long time ago.

There’s too much F# code in the wild now to be making major breaking changes.

2. Defaults matter, and those of us here who are F# fans are fans because we like these defaults. We *want* it to be harder to write OO and imperative code than to write functional code. That’s what it means to have a multiparadigm functional-first language.

If you want to write in a language with a different primary paradigm, don’t use F#.

Notice that I’m not telling you that you’re wrong to want something else. We have so many popular programming languages because not everyone wants the same things. I prefer to have lots of choices. I use many languages myself, because there is no single language good for all things. (Not even F#.)

The people who make me nervous are those who think we must do everything in C, or Java, or Python. It feels like “My Favorite Language Über Alles!” It makes me wonder what other intolerances such people harbor.
Reply all
Reply to author
Forward
0 new messages