07 March 2026

Functions in F#

In learning about F#, one of the first things I had to come to terms with is that all F# functions have only one input and only one output.

This is a strange thing to understand when you’re allowed to write things like:

> let add x y = x + y;;

Even though it’s clear we’re returning one integer, it sure looks like we’re passing two arguments to add.

In reality, what’s happening becomes a bit clearer if we examine the function’s type signature:

val add: x: int -> y: int -> int

What this is saying is that add is a function that takes an int x and returns a function that takes int y and returns an int. Think of each arrow (->) as a function that takes the parameter from the left and returns the value to the right. This is called Currying, which is apparently named after the guy who invented Haskell.

Therefore, we can pass an integer, say 5, to the function add, and it will return another function which will take an interger, add it to 5, and then return the result. If we name that new function add5, we can define it as follows:

> let add5 = add 5;;

which gives us the type signature of

val add5: (int -> int)

Calling add5 with another integer gives us the sum:

> add5 4;;
val it: int = 9

> add5 -7;;
val it: int = -2

We can also partially define other such functions by just passing the first argument to add:

> let add7 = add 7;;
val add7: (int -> int)

> let add10 = add 10;;
val add10: (int -> int)

> add7 4;;
val it: int = 11

> add10 20;;
val it: int = 30

Unsurprisingly, this concept is called Partial Application.

06 March 2026

Learning Functional Programming with F#

I'm not a programmer by profession or trade but I've always enjoyed working with computers and have dabbled in programming for as long as I've been able to access computers.  I've done the usual tour of duty using languages such as Basic, Python, Fortran, C, C#, D and Perl but I would not consider myself an expert in anything of them.  I can write simple imperative programs using control loops, if/else statements and generally know how functions, procedures or methods work in most of these languages.

For some reason though, I've never been able to wrap my head around functional programming and, until recently, never could properly define what it is.  Technically, I probably still can't but am getting to grips on what concepts functional programming entails and what behaviors it encourages.  So over the past few weeks, I've been trying to pick it up some using F#.  While most imperative languages, including C#, Perl and others can accommodate functional programming aspects, I thought I would try one of the ML-inspired languages to begin this journey.  I've already had .NET installed on my machine as I was learning C# so rather than install a whole new language or framework, I thought I would check out Microsoft's version of a functional language.  Haskell, OCaml and other languages still seem too esoteric and arcane to me but I know they have large followings devoted practitioners.

My original thought was to start by going through some functional programming books to begin my journey but the two most promising ones I could find "Grokking Functional Programming" and "Functional Programming in Scala" both use Scala as the language to convey functional programming concepts.  While both books state that the actual language doesn't really matter, I couldn't get past the unfamiliar syntax which distracted my ability to focus on the underlying theory of functional programming.  While it probably would have just been easier to install Scala and get on with it, I really didn't want to have both .NET and JDK on my machine.

For now, I am trying to go through Isaac Abraham's "F# in Action".  While it does espouse functional programming paradigms, it focuses more on introducing the reader to the fundamental aspects of the language itself which is what I really think I need.

I'm going to be sharing short snippets of what I learn and find interesting, more as a journal to remind myself of what I cover but would definitely appreciate any feedback, suggestions or comments from anyone who comes across these missives.