I hereby claim:
- I am epfahl on github.
- I am udikorn (https://keybase.io/udikorn) on keybase.
- I have a public key ASC-Qn48i6lXIbcY44rIuSgaliYNzJ_WgOqFQnKL9gqdZAo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
| # Discussed in https://www.ericpfahl.com/from-pattern-matching-to-unification/ | |
| defmodule Var do | |
| alias Var | |
| @type t :: %Var{id: any} | |
| defstruct [:id] | |
| @spec new(any) :: Var.t() | |
| def new(id), do: %Var{id: id} |
| # Discussed in https://www.ericpfahl.com/beyond-unification-a-basic-logical-toolkit/ | |
| defmodule L3.Var do | |
| alias L3.Var | |
| @type t :: %Var{id: any} | |
| defstruct [:id] | |
| @spec new(any) :: Var.t() | |
| def new(id), do: %Var{id: id} |
| defmodule MergeSort do | |
| @spec sort(list()) :: list() | |
| def sort([]), do: [] | |
| def sort([h]), do: [h] | |
| def sort([_ | _] = list) do | |
| {left, right} = divide(list) | |
| left_sorted = sort(left) | |
| right_sorted = sort(right) |
| defmodule Exp do | |
| def draw() do | |
| x = :rand.uniform() | |
| draw(x, x, 1, 0) | |
| end | |
| defp draw(x, u, n, k) do | |
| u_next = :rand.uniform() | |
| if u > u_next do |
| defmodule Quicksort do | |
| @spec sort([any()], :asc | :desc) :: [any()] | |
| def sort(values, direction \\ :asc) do | |
| sorted = sort(values) | |
| if direction == :asc do | |
| sorted | |
| else | |
| Enum.reverse(sorted) | |
| end |
| defmodule PLF do | |
| @doc """ | |
| Given a list of `{x, y}` nodes that the function must pass through, return | |
| a function any input `x`. | |
| For inputs less than the minimum `x` values among the nodes, extrapolate | |
| with a constant equal to the `y` value of the min-`x` node. Similar | |
| extrapolation occurs for `x` larger than the max-`x` node. | |
| Note: When the number of nodes is large, this can be made more efficient |