background preloader

Functional

Facebook Twitter

Funktionale Programmierung — Video-AG, Fachschaft I/1, RWTH Aachen. Research papers/Functional pearls. You Could Have Invented Monads! (And Maybe You Already Have.) If you hadn't guessed, this is about monads as they appear in pure functional programming languages like Haskell.

You Could Have Invented Monads! (And Maybe You Already Have.)

They are closely related to the monads of category theory, but are not exactly the same because Haskell doesn't enforce the identities satisfied by categorical monads. Writing introductions to monads seems to have developed into an industry. There's a gentle Introduction, a Haskell Programmer's introduction with the advice "Don't Panic", an introduction for the "Working Haskell Programmer" and countless others that introduce monads as everything from a type of functor to a type of space suit.

But all of these introduce monads as something esoteric in need of explanation. But what I want to argue is that they aren't esoteric at all. Many of the problems that monads try to solve are related to the issue of side effects. Side Effects: Debugging Pure Functions In an imperative programming language such as C++, functions behave nothing like the functions of mathematics. Solution and. Reusing Thunks for Recursive Data Structures in Lazy Functional Programs - Yasunao TAKANO. Writing a Raytracer in Common Lisp - Part 1. How would I even use a monad (in C#)? How would I even use a monad (in C#)?

How would I even use a monad (in C#)?

As you may have guessed, based on everyone ever trying to explain what they are, monads are an interesting concept. I assume the difficulty in explaining them stems from the high level of abstraction, compared to related ideas like “being enumerable”, but I won’t be trying to explain what a monad is in this post. Instead I’m going to show you how, in C#, you can take advantage of a type being a monad. If you do want an explanation of what a monad is, I recommend the marvels of monads, an old post that made the concept “click” for me.

It even covers some of the same content I’ll be presenting here. Querying your Monad Language integrated query (LINQ) was a major feature introduced way back in C#3. // before linqvar transformedList = new List();foreach (var item in inputList) { transformedList.Add(item * 2 + 1);}// after linqvar transformedSequence = from item in inputList select item * 2 + 1; public static void PrintQueryNullables() { int? Hybrid Queries. The Lambda Calculus. First published Wed Dec 12, 2012; substantive revision Fri Feb 8, 2013 The λ-calculus is, at heart, a simple notation for functions and application.

The Lambda Calculus

The main ideas are applying a function to an argument and forming functions by abstraction. The syntax of basic λ-calculus is quite sparse, making it an elegant, focused notation for representing functions. Functions and arguments are on a par with one another. The result is an intensional theory of functions as rules of computation, contrasting with an extensional theory of functions as sets of ordered pairs. 1. The λ-calculus is an elegant notation for working with applications of functions to arguments. Λx[x2 − 2·x + 5]. The λ operators allows us to abstract over x. The first step of this calculation, plugging in ‘2’ for occurrences of x in the expression ‘x2 − 2·x + 5’, is the passage from an abstraction term to another term by the operation of substitution. (β) (λx[M])N ⊳ M[x := N] 1.1 Multi-argument operations. The Lambda Calculus. Introduction.

This blog will follow my steps toward learning F#.

Introduction

I am hoping to use F# and XNA to write small games for the XBox 360. I have no idea yet on the feasibility of that, but if it works, it would open a whole world of fun opportunities. I would normally not write a tutorial about something I don't know, but seeing the current lack of tutorials for F#, it might be beneficial for others to follow my progress. (UPDATE: Gosh, I can sure sound pretentious sometimes... the tutorials that do exist are pretty good.

See for instance F# in 20 minutes. I will start with a series of tutorials dedicated to implementing a Runge-Kutta integrator. I will not explain how to install and set up an F# development environment, that information is available on the net. Macros vs. Monads.