Wednesday, December 2, 2015

The First Post

Motivation for this blog

I recently graduated my masters degree in computer science, specializing in Dependent Types (functional programming) and teaching. As such, I have strong interests in high quality software, and knowledge sharing. These are the focuses of this blog. My hope is that this blog will be mutually beneficial for readers and me through code sharing and community interaction. For clarity, I have chosen to focus on two topic. In particular I have chosen Customer Relationship Management (abbr: CRM) systems and Functional Programming (abbr: FP) because I think they are interesting, relevant, and current topics.

CRM

The CRM system I consider is Microsoft Dynamics CRM, mostly online, however there might be the occasional post about on-premise. One of my goals is to be up-to-date so I mostly post about 2015 (until CRM 2016 goes live), but when I build software it should support all the Microsoft supported versions.

Functional Programming

I come from a background in OCaml programming, but am in the process of switching to F#. It works better with CRM, thus making for a more consistent blog. Since most (functional) OCaml code is also valid F# code the switch is pretty seamless, however I still have some style-artifacts.

Format

As this is a technical blog, I try to include code as much as possible. I agree with Martin Fowlers statement that comments are often used to cover up bad code, therefore I stride for my code to be self-documenting. Apart from that, the format depends wither the post is about CRM or FP.

CRM

For CRM, the code will probably be more complex and focusing on software architecture. In technical CRM posts there are always two perspectives: how to build it, and how to use it, I intend to split these into separate posts, hoping that each will be more clear. When I do less technical posts, I intend to include as many screenshots as possible.

Functional Programming

For FP I usually try to make my demonstrations small'n'cute, presenting concepts in a clear, down-to-earth manner. As I am a teacher by heart, I may occasionally post tutorials or exercises, intended to teach useful techniques in a safe and guided fashion.

Some code

As mentioned, I try to post code as much as possible, so here is this posts share.

I was recently challenged by a colleague to make a (Pure) list library where appending was O(1) without using the lazy-keyword. As suggested by the formulation he expected me to implement lazyness through explicit thunks.

type 'a mylist_lazy =
  | Nil
  | Cons of 'a * (unit -> 'a mylist_lazy)

I leave the rest of this library as an exercise for the reader.

However, there is another way to implement such lists, which is quite neat. The key idea is to have a pointer to the end of the list, but because the solution has to be pure, we cannot use references. What we can use however is functions. The intuition is that we postpone putting in the list terminator (nil). Equationally we see:

1 :: 2 :: 3 :: nil = (fun tl -> 1 :: 2 :: 3 :: tl) nil

So, instead of returning lists we return a function taking the tail of the list and returning the final list. Append now just becomes the function composition of two mylists.

type 'a mylist = 'a list -> 'a list
let nil = fun tl -> tl
let cons x xs' = fun tl -> x :: xs' tl
let append xs ys = fun tl -> xs (ys tl)
let is_empty xs = (* exercise *)
let head xs = (* exercise *)
let tail xs = (* exercise *)
let map f xs = (* exercise *)
let to_list xs = (* exercise *)

No comments:

Post a Comment