Skip to content

Instantly share code, notes, and snippets.

@lambdageek
Last active August 29, 2015 14:11
Show Gist options
  • Save lambdageek/2e752662c5e91917de5c to your computer and use it in GitHub Desktop.
Save lambdageek/2e752662c5e91917de5c to your computer and use it in GitHub Desktop.

Consider the following (not particularly useful) Haskell function

  f :: forall a . Eq a => a -> a -> ()
  f x y = if x == y then f [x, x] [y, y] else ()

My understanding is that this would be translated to something like

  functor F (struct X : sig type a
                            structure Eq : EQ where type t = a
                        end) = struct
    structure Xinst = struct
      type a = X.a list
      structure Eq = EqList (Eq)
    end
    structure Finst = F (Xinst) 
    fun f x y = if Eq.== x y then Finst.f [x, x] [y, y] else ()
  end

But note that we use F in the body of F in order to call f at the type a list in the recursive call.

It seems like one may claim that typeclasses are merely a mode of use of the ML+recursive modules. But that's an awful lot of machinery to bring along.

@skilpat
Copy link

skilpat commented Dec 18, 2014

Adding this twitter thread for reference: https://twitter.com/lambdageek/status/544610916869079041

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment