Skip to content

Instantly share code, notes, and snippets.

@deech
Created February 16, 2017 02:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save deech/39b63fc1543c47af3da60a161fcd739f to your computer and use it in GitHub Desktop.
Save deech/39b63fc1543c47af3da60a161fcd739f to your computer and use it in GitHub Desktop.
(datatype is-prime
if (is-prime? N)
N : number;
==============
N : prime;)
(define is-prime?
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:
(13+) 1 : prime
1 : prime
(14+) 2 : prime
type error
*\
@shanecelis
Copy link

Turn on the Shen type checker with (tc +) to replicate example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment