Skip to content

Instantly share code, notes, and snippets.

View evansb's full-sized avatar

Evan Sebastian evansb

  • Singapore
View GitHub Profile
@evansb
evansb / Cont.hs
Created January 18, 2015 13:14
Continuation Passing Style in Haskell
{-# LANGUAGE InstanceSigs #-}
import Control.Applicative
import Control.Monad
import Control.Monad.Trans.Writer
-- Here is a direct style pythagoras function
-- There are two noticeable things in the function body.
-- 1. Evaluation order of x * x vs y * y is unknown/implicit.
-- 2. We don't care what happens to the final value (implicit continuation).
pyth :: (Floating a) => a -> a -> a
@evansb
evansb / shunt.hs
Created June 6, 2014 14:22
Shunting Yard Algorithm in Haskell
module Main where
import Data.Char
import Data.Map
-- Shunting - Yard algorithm for Reverse Polish Notation
data Token = Number Int | ParenOpen | ParenClose
| AddOp | MulOp | DivOp | SubOp
deriving (Show, Eq)