Skip to content

Instantly share code, notes, and snippets.

@StoneCypher
Created January 26, 2014 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StoneCypher/8639571 to your computer and use it in GitHub Desktop.
Save StoneCypher/8639571 to your computer and use it in GitHub Desktop.
-module(wm). % wrap math
-compile(export_all).
%% 2> c("/projects/scratch/wm.erl").
%% {ok,wm}
%%
%% 3> wm:one().
%% #Fun<wm.0.45968298>
%%
%% 4> F = wm:one().
%% #Fun<wm.0.45968298>
%%
%% 5> F().
%% 1
%%
%% 6> G = wm:triple(wm:one()).
%% #Fun<wm.1.45968298>
%%
%% 7> G().
%% 3
%%
%% 8> H = wm:triple(wm:triple(wm:one())).
%% #Fun<wm.1.45968298>
%%
%% 9> H().
%% 9
%%
%% 10> I = wm:triple(wm:add_two(wm:triple(wm:one()))).
%% #Fun<wm.1.45968298>
%%
%% 11> I().
%% 15
one() -> fun() -> 1 end.
const_multiply(Const, Wrapped) ->
fun() -> Const * Wrapped() end.
double(Wrapped) ->
const_multiply(2, Wrapped).
triple(Wrapped) ->
const_multiply(3, Wrapped).
const_add(Const, Wrapped) ->
fun() -> Const + Wrapped() end.
add_two(Wrapped) ->
const_add(2, Wrapped).
subtract_three(Wrapped) ->
const_add(2, Wrapped).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment