Skip to content

Instantly share code, notes, and snippets.

@shanecelis
Forked from deech/is-prime.shen
Last active Feb 16, 2017
Embed
What would you like to do?
(datatype is-prime
if (is-prime? N)
N : number;
==============
N : prime;)
(define is-prime?
2 -> true
X -> (prime* X (/ X 2) 2) where (number? X)
_ -> false)
(define prime*
X Max Div -> false where (integer? (/ X Div))
X Max Div -> true where (> Div Max)
X Max Div -> (prime* X Max (+ 1 Div)))
\*
Sample REPL interaction:
(12-) (tc +) \* Turn on the type checker. *\
true
(13+) 1 : prime
1 : prime
(14+) 2 : prime
type error
*\
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment