This file contains hidden or 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 | |
| TemplateHaskell, | |
| Rank2Types, | |
| NoMonomorphismRestriction, | |
| TypeOperators, | |
| StandaloneDeriving, | |
| DeriveFunctor #-} | |
| import Control.Applicative |
This file contains hidden or 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
| def split(list): | |
| "[a] -> (a, [a])" | |
| return [list[0], list[1:]] | |
| def reduce(list, zero, add): | |
| "([a], b, (b, a) -> b) -> b" | |
| for i in range(0, len(list)): | |
| zero = add(zero, list[i]) |
This file contains hidden or 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
| -- Wrapper for recursive types | |
| data Fix f = In { out :: f (Fix f) } | |
| -- 1-layer fold and unfold | |
| type Algebra f a = f a -> a | |
| type Coalgebra f a = a -> f a | |
| cata :: Functor f => Algebra f b -> Fix f -> b | |
| ana :: Functor f => Coalgebra f a -> a -> Fix f |
This file contains hidden or 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
| #lang racket | |
| (define (partition good? list return) | |
| (match list | |
| [(list) | |
| (return `() `())] | |
| [(list head tail ...) | |
| (partition good? tail (λ (accepted rejected) |
This file contains hidden or 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 RankNTypes #-} | |
| import Data.Traversable (for) | |
| import Data.Functor.Identity | |
| import Data.Functor.Constant | |
| type Lens s t a b = forall f . Applicative f => (a -> f b) -> (s -> f t) |
This file contains hidden or 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
| #lang racket | |
| ; await (s -> (s, parser)) | |
| ; yield (result, parser) | |
| ; stop (error) | |
| (define (await state-transform) `(await ,state-transform)) | |
| (define (yield result next) `(yield ,result ,next)) | |
| (define (stop error) `(stop ,error)) |
This file contains hidden or 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
| let getline return = | |
| getchar -> c: | |
| if equal c "\n" ? | |
| return "" | |
| else | |
| getline -> s: | |
| return (+ c s); | |
| let putline string next = |
This file contains hidden or 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 AST where | |
| data AST var | |
| = Constant String | |
| | Variable var String | |
| | (:->) [var] (AST var) | |
| | Call (AST var) [AST var] |
This file contains hidden or 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
| not_implemented = function () { | |
| throw "Implement me!" | |
| } | |
| map_list = not_implemented | |
| map_nullable = not_implemented | |
| map_function = not_implemented | |
| assert_equal = function (x, y) { |
This file contains hidden or 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
| require 'gtk3' | |
| class App | |
| def self.create &block | |
| @@framestack = [Gtk::Window.new] | |
| @@registration_on = true | |
| flow { self.instance_eval &block } |