Skip to content

Instantly share code, notes, and snippets.

View kseo's full-sized avatar

Kwang Yul Seo kseo

  • CodeChain
  • Seoul
View GitHub Profile
@kseo
kseo / Reduce.hs
Created January 27, 2016 02:40
Reduce
class Reduce t where
reducer :: (a -> b -> b) -> (t a -> b -> b)
reducel :: (b -> a -> b) -> (b -> t a -> b)
instance Reduce [] where
reducer f x z = foldr f z x
reducel f x z = foldl f x z
toList :: (Reduce f) => f a -> [a]
toList s = s `cons` [] where cons = reducer (:)
@kseo
kseo / Option.cs
Created January 19, 2015 07:00
Step by step implementation of Option type in C#
using System;
namespace Option
{
public abstract class Option<T>
{
public abstract T Value { get; }
public abstract bool IsSome { get; }
@kseo
kseo / Hello.hs
Created March 11, 2014 01:38
Fay Node.js Hello example
{-# LANGUAGE EmptyDataDecls #-}
module Hello where
import FFI
data Http
data HttpServer
data Request
data Response
@kseo
kseo / recon.ml
Last active March 28, 2024 14:41
A Hindley-Milner type inference implementation in OCaml
#! /usr/bin/env ocamlscript
Ocaml.ocamlflags := ["-thread"];
Ocaml.packs := [ "core" ]
--
open Core.Std
type term =
| Ident of string
| Lambda of string * term
| Apply of term * term
@kseo
kseo / IntMap.hs
Created February 14, 2014 04:35
A Haskell implementation of Okasaki and Gill's Fast Mergeable Integer Maps
module IntMap where
import Data.Bits
import Prelude hiding (lookup)
-- Fast Mergeable lnteger Maps*
-- http://ittc.ku.edu/~andygill/papers/IntMap98.pdf
-- Little-endian implementation
type Key = Int
@kseo
kseo / QuickUnion.hs
Last active July 31, 2023 13:53
The weighted quick-union with path compression algorithm
import Control.Monad
import Control.Monad.ST
import Data.Array.MArray
import Data.Array.ST
import Data.STRef
import Prelude hiding (id)
data UnionFind s = UnionFind {
ids:: STUArray s Int Int
@kseo
kseo / CombinatorParser.hs
Created December 20, 2013 03:10
Monadic Parsing in Haskell
module CombinatorParser where
import Control.Monad
import Data.Char
-- FUNCTIONAL PEARLS: Monadic Parsing in Haskell
-- http://eprints.nottingham.ac.uk/223/1/pearl.pdf
newtype Parser a = Parser { parse :: (String -> [(a, String)]) }
@kseo
kseo / FindEnumerator.hs
Last active December 31, 2015 19:49
find written in Haskell
-- From A tutorial on the enumerator library
-- http://www.mew.org/~kazu/proj/enumerator/
import Control.Applicative
import Control.Monad
import Control.Monad.IO.Class
import Data.Enumerator hiding (map, filter, filterM)
import qualified Data.Enumerator.List as EL
import Data.List
import System.Directory
import System.FilePath
@kseo
kseo / WCEnumerator.hs
Last active December 31, 2015 19:09
wc written in Haskell using enumerator
import qualified Data.ByteString as BS
import qualified Data.ByteString.Internal as BS (c2w, w2c)
import Data.Enumerator hiding (head)
import qualified Data.Enumerator.Binary as EB
import qualified Data.Enumerator.List as EL
import System.Environment
countLines :: Iteratee BS.ByteString IO Int
countLines = do
bs <- EL.head