Skip to content

Instantly share code, notes, and snippets.

:- module(csv_writer, [csv_write/3, csv_write_row/1, csv_flush/0]).
:- use_module(util, [rational_string/3, get_keypath_dict/3, rtrim/3]).
:- meta_predicate csv_write(+, +, 0).
csv_write(Path, Fields, Goal) :-
open(Path, write, Out),
maplist(term_to_atom, Fields, AtomFields),
Row =.. [row | AtomFields],
@esad
esad / delstreams.pl
Created February 1, 2020 15:26
Prolog lazy streams using delimited continuations
:- module(delstreams).
ask(_, 0, _) :- throw(asked_closed_stream).
ask(El, Stream, Stream2) :- reset(Stream, El, Stream2), (Stream2 \= 0).
take(0, _) :- !.
take(N, S) :- N > 0, ask(El, S, S1), shift(El), succ(N1, N), take(N1, S1).
drop(0, S) :- !, call(S).
drop(N, S) :- N > 0, ask(_, S, S1), succ(N1, N), drop(N1, S1).
@esad
esad / test.pl
Created June 18, 2019 11:53
Reversible dcg rules
:- op(1200, xfx, <-->).
:- use_module(library(dcg/basics), [digit//1]).
conj_rev(Term, Term) :- \+ Term = (_, _).
conj_rev((Term1,Term2), (Term2, T)) :- conj_rev(Term1, T).
term_expansion(<-->(X, Y), T) :- conj_rev(Y, YRev), dcg_translate_rule(X --> YRev, T).
term_expansion(<-->(X, Y), T) :- dcg_translate_rule(X --> Y, T).

Keybase proof

I hereby claim:

  • I am esad on github.
  • I am esad (https://keybase.io/esad) on keybase.
  • I have a public key ASAfen-9PxDRLHSaNvxQ9Xz73TqSHasb41ifGZG90eNejAo

To claim this, I am signing this object:

type Foo<'a> = Foo of string
let get (Foo key : Foo<'a>) : 'a option =
None
let set (Foo key : Foo<'a>) (value : 'a) =
()
let f = Foo "test"
type ItemRef = Int
newtype Item = Item
{ text :: String
, done :: Boolean
, ref :: ItemRef
}
derive instance newtypeItem :: Newtype Item _
module X where
import Data.Newtype
import Data.Lens (Lens')
import Data.Lens.Iso.Newtype (_Newtype)
newtype X = X Int
ten = X 10
modify' f = do
modify f
state <- get
localStorage <- fromEff getLocalStorage
fromEff $ setItem localStorage stateKey state
foreign import md5 :: String -> String
infixl 1 applyFlipped as |>
findPassword :: String -> String
findPassword doorId =
aux 0 Nil
where
aux :: Int -> List Char -> String
aux k cs =
case (doorId <> (show k)) |> md5 |> String.toCharArray |> List.fromFoldable of
module PouchDB where
import Task
import Json.Decode exposing (..)
import Native.PouchDB
type PouchDB = PouchDB
type alias Document a =