Skip to content

Instantly share code, notes, and snippets.

@chryslovelace
Last active March 12, 2019 21:17
Show Gist options
  • Save chryslovelace/2d0e08e0e3dab5aaaa9c849c36e38065 to your computer and use it in GitHub Desktop.
Save chryslovelace/2d0e08e0e3dab5aaaa9c849c36e38065 to your computer and use it in GitHub Desktop.
tuesday
// compile with `gcc -shared -o tuesday.so tuesday.c`
#include <time.h>
int day_of_week()
{
time_t t;
time(&t);
return localtime(&t)->tm_wday;
}
module Main
%dynamic "./tuesday.so"
dayOfWeek : IO Int
dayOfWeek = foreign FFI_C "day_of_week" (IO Int)
isItTuesday : IO (Provider ())
isItTuesday = do day <- dayOfWeek
pure $ if day == 2 then Provide () else Error "it's not tuesday!!!"
%language TypeProviders
%provide (tuesday : Unit) with isItTuesday
main : IO ()
main = pure tuesday
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment