Skip to content

Instantly share code, notes, and snippets.

View DRouh's full-sized avatar

Dime Rouh DRouh

View GitHub Profile
@DRouh
DRouh / coconway.fs
Last active February 24, 2019 16:24
Comonadic Game of Life (an F# port of https://eli-jordan.github.io/2018/02/16/life-is-a-comonad/)
module ConsoleApp1.Program
type Store<'s, 'a> = Store of lookup : ('s -> 'a) * index : 's
type Coord = int * int
type Grid<'a> = Store<Coord, 'a>
module Utils =
let getOrDefault k d m =
m |> Map.tryFind k |> (function | Some(v) -> v | None -> d)
@DRouh
DRouh / tree traversal.fsx
Last active January 27, 2019 14:07
breadth, depth tree traversal
type BinaryTree<'a> =
| Empty
| Node of value: 'a * left: BinaryTree<'a> * right: BinaryTree<'a>
let rec traverse f =
function
| Empty -> []
| node -> f node
let rec inorder =
#!/usr/bin/env stack
-- stack --resolver lts-9.17 --install-ghc runghc --package ilist
import Data.List.Index
main :: IO ()
main = print $ indexed "example"
@DRouh
DRouh / rss_script.hs
Last active December 16, 2017 06:05
Haskell Stack-based script sample. Fetching a list of RSS feeds and creating an HTML summary with all the links.
#!/usr/bin/env stack
-- stack --resolver lts-9.17 script
{-# LANGUAGE QuasiQuotes #-}
module Main where
import Data.ByteString.Lazy (ByteString)
import Data.ByteString.Lazy.UTF8 (toString)
import Data.List (find)
import Data.Maybe
import Data.String.Here
import GHC.IO.Encoding