This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveFunctor #-} | |
{-# LANGUAGE DeriveFoldable #-} | |
{-# LANGUAGE DeriveTraversable #-} | |
module Program where | |
import Data.Foldable | |
import Data.Traversable | |
import Prelude hiding (lookup) | |
import Control.Monad.State |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
NewerOlder