Skip to content

Instantly share code, notes, and snippets.

View holoed's full-sized avatar
😀

Edmondo Pentangelo holoed

😀
View GitHub Profile
@holoed
holoed / AnaCataFactorial.hs
Created March 27, 2016 16:29
Ana-Cata (Hylo) Factorial
{-#LANGUAGE DeriveFunctor#-}
module Main where
fix :: ((a -> b) -> a -> b) -> a -> b
fix f = f (fix f)
data Fix f = In { out :: f (Fix f) }
ana :: Functor f => (a -> f a) -> (a -> Fix f) -> a -> Fix f
@holoed
holoed / ExpTransform.hs
Last active January 27, 2016 08:36
Experiments in Generic Traversal of an AST
{-# LANGUAGE DeriveFunctor #-}
module Compiler.Transformations.Experiments where
import Control.Monad.State
import Text.Printf
data ExpF a = Var String
| Lam [String] a
| App a a deriving (Functor)
@holoed
holoed / Cata.hs
Created December 20, 2015 16:24
Experiments in Cata
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
module Program where
import Data.Foldable
import Data.Traversable
import Prelude hiding (lookup)
import Control.Monad.State
@holoed
holoed / Lenses.scala
Created September 13, 2015 19:27
Scala Lenses
/**
* Created by epentangelo on 27/08/2015.
*/
object Lenses {
type Lens [a, b] = (a => b, a => b => a)
def makeLens[a, b](get: a => b, set: a => b => a) : Lens[a, b] = (get, set)
def get[a, b] (lens: Lens[a, b]) (obj: a) : b = lens._1(obj)
@holoed
holoed / ContM.js
Last active August 29, 2015 14:27
JavaScript Async function compositions through the Continuation Monad
// unit :: a -> m a
const unit = x => c => c (x)
// bind :: m a -> (a -> m b) -> m b
const bind = m => f => c => m (x => f(x)(c))
// map :: ma -> (a -> b) -> m b
const map = m => f => bind (m) (x => unit(f(x)))
// foldr :: (a -> b -> b) -> b -> [a] -> b
@holoed
holoed / Lenses_Experiments.hs
Last active August 29, 2015 14:26
Simple experiment creating Lenses
module Main where
import Prelude (String, Show, print, flip, IO)
import Control.Category
data Lens a b = L ( a -> b, -- getter
b -> a -> a ) -- setter
mkLens :: (a -> b) -> (b -> a -> a) -> Lens a b
mkLens g s = L (g, s)