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
(define (amb-fail f) | |
(error "amb" "Unable to satisfy conditions")) | |
(define (amb . it) | |
(define old amb-fail) | |
(call/cc (lambda (top) | |
(map (lambda (val) | |
(call/cc (lambda (cont) | |
(set! amb-fail cont) |
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 ViewPatterns #-} | |
import Data.List | |
import Data.Maybe | |
data Tree a = Node{value :: a, subtree :: [Tree a]} | |
deriving (Eq, Show) | |
type Trie = Tree Char | |
toTrie :: String -> Trie | |
toTrie (reverse -> c : s) = foldl' (flip Node . (:[])) (Node c []) s |
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
import Control.Monad.State | |
import Control.Monad.Error | |
import Control.Applicative | |
type Sym = Int | |
data Term = Box Int | |
| Star | |
| Abs Term (Term -> Term) | |
| App Term Term | |
| Forall Term (Term -> Term) |
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
This is my short-ish tutorial on how to implement closures in | |
a simple functional language: Foo. | |
First, some boilerplate. | |
> {-# LANGUAGE DeriveFunctor, TypeFamilies #-} | |
> import Control.Applicative | |
> import Control.Monad.Gen | |
> import Control.Monad.Writer | |
> import Data.Functor.Foldable |
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
### Keybase proof | |
I hereby claim: | |
* I am jozefg on github. | |
* I am jozefg (https://keybase.io/jozefg) on keybase. | |
* I have a public key whose fingerprint is F6CF 1EA2 013C 8700 D24B 030D D5DC A663 AAE6 2FAE | |
To claim this, I am signing this object: |
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 RecordWildCards #-} | |
module Unify where | |
import Control.Monad.Logic | |
import qualified Data.Map as M | |
type Id = Integer | |
type Atom = String | |
data Term = Var Id | |
| Atom Atom |
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
term : type. | |
and : term -> term -> term. | |
or : term -> term -> term. | |
imp : term -> term -> term. | |
top : term. | |
hyp : term -> type. | |
true : term -> type. | |
init : true A |
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 FunctionalDependencies #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE DeriveTraversable #-} | |
{-# LANGUAGE DeriveFoldable #-} | |
{-# LANGUAGE DeriveFunctor #-} | |
module Main where | |
import Data.Foldable | |
import Data.Traversable | |
import Data.Monoid |
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
use std::io::stdin; | |
fn fizzbuzz (n : int) -> String { | |
match (n % 3 == 0, n % 5 == 0) { | |
(true, true) => "FizzBuzz".to_string(), | |
(false, true) => "Fizz".to_string(), | |
(true, false) => "Buzz".to_string(), | |
(false, false) => n.to_string() | |
} | |
} |
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
enum Tree<A> { | |
Leaf(A), | |
Node(Box<Tree<(A, A)>>) | |
} | |
fn size<A>(t : &Tree<A>) -> int { | |
match t { | |
&Leaf(_) => 1, | |
&Node(box ref t) => size(t) | |
} |
OlderNewer