import std/io // The HTTP-router match of issue #295 (a string and a list of strings): // its decision tree's leaves call the arms' lifted continuations, so the // Core is linear in the arms. fn route :: method: String segments: List -> String { match (method, segments) { ("GET", ["archive"]) -> "archive" , ("GET", ["search"]) -> "search" , ("GET", ["trash"]) -> "trash" , ("GET", ["label", label]) -> "label " <> label , ("POST", ["notes", note]) -> "revise " <> note , ("GET", ["notes", note, "edit"]) -> "edit " <> note , ("POST", ["notes", note, "tag"]) -> "tag " <> note , ("POST", ["notes", note, verb]) -> verb <> " " <> note , _ -> "missing" } } pub fn main :: -> () / { io.println (route "POST" ["notes", "n", "pin"]) io.println (route "GET" ["archive"]) io.println (route "GET" ["search"]) io.println (route "GET" ["trash"]) io.println (route "GET" ["label", "x"]) io.println (route "POST" ["notes", "n"]) io.println (route "GET" ["notes", "n", "edit"]) io.println (route "POST" ["notes", "n", "tag"]) io.println (route "PUT" ["archive"]) io.println (route "GET" []) io.println (route "GET" ["archive", "extra"]) } //> pin n //> archive //> search //> trash //> label x //> revise n //> edit n //> tag n //> missing //> missing //> missing