// A tuple pattern inside a constructor pattern, when a later field of // the same constructor is tested too (`[(tag, n)]`: the head's tuple, // then the tail is `[]`): the simplifier sinks the projection of `tag` // into the branch that knows the tail, and must keep the tuple's `let` // it reads (issue #433). It was dropped as dead: the interpreter // panicked reading an unbound variable, native code segfaulted. import std/io import std/list type Pair { Pair(left: (String, Int), right: Bool) } fn only :: points: List<(String, Int)> -> Option { match list.reverse points { [(tag, n)] -> Some(tag), _ -> None } } fn leader :: points: List<(String, Int)> threshold: Int -> Option { let best = list.fold points 0 fn m p { if p.1 > m { p.1 } else { m } } match list.filter points fn p { p.1 == best } { [(tag, n)] if n >= threshold -> Some(tag), _ -> None } } fn post :: posts: List<(String, List<(String, String)>, String)> -> String { match posts { [(url, headers, body)] -> url <> " " <> body <> " " <> show (list.length headers) , other -> "posts: " <> show (list.length other) } } fn inner :: p: Pair -> String { match p { Pair((a, b), True) -> a <> show b, _ -> "no" } } pub fn main :: -> () / { io.println (show (only [("MRD", 4)])) //> Some(MRD) io.println (show (only [("MRD", 4), ("ORE", 1)])) //> None io.println (show (leader [("MRD", 12), ("ORE", 4)] 10)) //> Some(MRD) io.println (show (leader [("MRD", 4), ("ORE", 1)] 10)) //> None io.println (post [("https://a", [("k", "v")], "body")]) //> https://a body 1 io.println (post []) //> posts: 0 io.println (inner (Pair(("x", 2), True))) //> x2 io.println (inner (Pair(("x", 2), False))) //> no }