My Functional Programming Notes

DRAFT

These are concise, early learning functional programming notes from these sources:

Each of my notes has the following structure, and points that are [in brackets are my own intuitions].

Heading that can turn in to a question.

1. A series of phrases,  
2. each of which,  
3. is about this long,  
4. and that has,  
5. about seven (plus minus two) points,  
6. because that makes it,  
7. easy to read and to rehearse.  

Psuedo Code

The some pseudo-code shows the signatures of fundamental functional programming concepts in C# syntax. The comments above each shows the Haskell syntax and names some similar methods from C#.NET.

https://wiki.haskell.org/Typeclassopedia#Definition

public class MyFunctor<T>  
{
    public T Inner { get; }
    public MyFunctor(T inner) => Inner = inner;
}

public static class MyFunctorExtensions  
{
    // class Functor f where
    //  fmap :: (a -> b) -> f a -> f b
    public static MyFunctor<TResult> Fmap<TSource, TResult>(
        this MyFunctor<TSource> input,
        Func<TSource, TResult> func) => new MyFunctor<TResult>(func(input.Inner));
}

Programming Language Ancestry

ML  
  Standard ML
  Caml
    OCaml
      Rust
      F# <-----
SASL  
  Miranda
    Haskell
      Rust
      Swift
Lisp  
  Clojure 
Java  
  C#
  Scala

Map

  • aka fmap, Select
  • E<'T> -> ('T -> 'U) -> E<'U>
  • [projection]
  • applies a specified function
  • ... to the underlying value
  • ... of an elevated type.
  • the LINQ Select(...) method
  • ... is a map operation
  • ... on IEnumerable types.

Bind

  • aka flapMap, SelectMany
  • E<'T> -> ('T -> E<'U>) -> E<'U>
  • [projection to elevated]
  • the LINQ `SelectMany(...) method
  • ... is a bind operation
  • ... on IEnumerable types.

Apply

  • E<'T> -> E<('T -> 'U)> -> E<'U>
  • [elevated projection]

Pure

  • aka return
  • 'T -> E<'T>

Elevated Type

  • a container
  • wraps an underlying value
  • provides a context around that underlying value

Functor

  1. a context around a value
  2. supports the map/fmap operation
  3. [an IEnumerable in C# is like a functor,
  4. ...because IEnumerable supports Select]
  5. [A value in a computational context.]

Applicative functor

  • [A function in a computational context.]

Monad

  1. a context around a value
  2. supports the bind and return operations

Monoid

  • TODO
  • TODO

Type Class

  • [similar to C# interface but less powerful]