Month: October 2018

  • Folding Nonempty Lists in OCaml and Haskell

    Folding Nonempty Lists in OCaml and Haskell

    In the last post, I talked about catamorphisms in Haskell.  Specifically, the advantages of the foldr1 or foldl1 option in Haskell.  Namely, (1) not needing to specify the base case and (2) preserving polymorphisms in all applicable types.  In this post, I will show another way to fold nonempty list without using foldr1 or foldl1…

  • Programming with Bananas in Haskell (Versus OCaml)

    Programming with Bananas in Haskell (Versus OCaml)

    In the last post I talked about catamorphisms in OCaml.  In this post I compare that with Haskell.  We’ll see that Haskell gives you more options when implementing catamorphisms.  You don’t need to know Haskell to understand this post, I’ll introduce the required Haskell syntax along the way. Catamorphisms in Haskell As mentioned in the…

  • Programming with Bananas in OCaml

    Programming with Bananas in OCaml

    By bananas, I mean banana brackets as in the famous paper “Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire” by Meijer et al.  In this post I only focus on bananas, also called catamorphisms. Recursion is core to functional programming.  Meijer et al. show that we can treat recursions as separate higher order functions…

  • Structural Versus Physical Comparsions in OCaml

    Structural Versus Physical Comparsions in OCaml

    The comparison operators in OCaml are polymorphic.  That is, you can use them for various data types.  Because OCaml is a typed language, like any other operator, you have to apply them to the same type.  E.g., comparing a float to an int will give you a type error. OCaml can perform two types of…

  • Lexical Scoping in OCaml

    Lexical Scoping in OCaml

    Like many other modern languages, OCaml uses lexical (or static) scoping.  That is, in OCaml, when your function includes a name that calls a variable, in the function, that variable has the value when the function is defined.  The opposite is dynamic scoping, in which the variable has the value when the function is called. …