Basic unit type:
λ> replTy "()"
() :: ()
Basic functions:
# maybe.py - a Pythonic implementation of the Maybe monad | |
# Copyright (C) 2014. Senko Rasic <[email protected]> | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# |
Basic unit type:
λ> replTy "()"
() :: ()
Basic functions:
#include "stdio.h" | |
#include "stdlib.h" | |
unsigned int max(unsigned int a, unsigned int b) { | |
return a > b ? a : b; | |
} | |
unsigned int bucket(unsigned int val) { | |
return val & 0xF0000000 >> 28; | |
} |
Simplifying division of church-numbers with church-fractions.
A church number n
can be understood as the act of applying a function to a value n
times. That is:
(λ f x . (f (f (f x))))
Can be understood as the church number 3
, since it is an action that applies a function, f
, to a value, x
, 3 times. Here, I will be using "number" as a synonym for "church number" and, thus, a "natural number". Implementing addition, multiplication and exponentiation on church numbers is straightforward. Division is more awkward. Wikipedia, for instance, uses a recursive definition that doesn't have a normal form and is, thus, unsuited for strongly normalizing evaluators. This version is total, but has a huge normal form and works for integers, not naturals. There is a simpler way to define it, extending the same intuition to bu
This project has moved to https://github.com/jonhoo/drwmutex so it can be imported into Go applications.