Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am shonfeder on github.
  • I am shonfeder (https://keybase.io/shonfeder) on keybase.
  • I have a public key ASBDCrS3OyOBp9UsG6Hfu6NSm0zYEubj7ErZJjNSRyqe7wo

To claim this, I am signing this object:

@shonfeder
shonfeder / maybe_monad.pl
Created December 13, 2016 06:30
The maybe monad, hard coded in Prolog, just for fun and IRC play time.
maybe(just(_)).
maybe(nothing).
bind(nothing, _, nothing).
bind(just(A), P, M) :- call(P, A, M),
maybe(M).
return(X, just(X)).
maybe_div(_,0,nothing) :- !.
@shonfeder
shonfeder / cyclical-from-enum.hs
Created December 12, 2016 15:12
Cyclical data structure, I saw this on some SO answer
class (Enum a, Bounded a, Eq a) => Cyclical a where
next :: a -> a
next a = if a == maxBound then minBound else succ a
prev :: a -> a
prev a = if a == minBound then maxBound else pred a
data Direction = North | East | South | West
deriving (Show, Enum, Bounded, Eq)
instance Cyclical Direction
@shonfeder
shonfeder / advent-throw-away-day-1.sml
Created December 12, 2016 15:09
Gist of an advent of code semi-solution
(* either turn left (L) or right (R) 90 degrees, then walk forward the given number of blocks, ending at a new intersection. *)
(* Relative *)
datatype relative_direction = L | R
type distance = int
datatype instruction = Inst of relative_direction * distance
fun dirFromChar c = case c of #"L" => L
| #"R" => R