Surprise! We've been running on hardware provided by BuyVM for a few months and wanted to show them a little appreciation.
Running a paste site comes with unique challenges, ones that aren't always obvious and hard to control. As such, BuyVM offered us a home where we could worry less about the hosting side of things and focus on maintaining a clean and useful service! Go check them out and show them some love!
Submitted on February 15, 2016 at 06:10 PM

Section 1 (OCaml)

****.mli file**

type ('k, 'v) trie

val empty : ('k, 'v) trie
val insert : ('k, 'v) trie -> 'k list -> 'v -> ('k, 'v) trie

****.ml file**

type ('k, 'v) trie = Trie of 'v option * (('k * ('k, 'v) trie) list)

(** The empty trie *)
let empty = Trie (None, [])

let rec insert t ks v =
    let (key, subtries) = t in
    match ks with
    |[] -> Trie (Some v, subtries)
    |k::krest -> (if (List.fold_left (equal_to k) false (List.map pair2key subtries)) then
        (* current k was pointing to one of the current subtries -- update it from now on *)
            (* Trie (key, subtries)  *)
            (* Trie (key, (List.map (fun (k,st) -> (k,st)) subtries))  *)
            Trie (key, (List.map (fun (k,st) -> (k,(insert st krest v))) subtries))
        else
        (* current k was not in this level -- make a new trie to continue *)
            Trie (key, subtries @ [k, (insert empty krest v)])
        )

***************************
the error:
***************************
File "trie.ml", line 23, characters 73-81:
Error: This expression has type ('a * ('a, 'b) trie) list
       but an expression was expected of type
         ('c * ('b option * ('a * ('a, 'b) trie) list)) list