Total (non-error-throwing) lambda-calculus evaluators.
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
| -- | Our main engine for naming a value, then we can prove properties about a named value. | |
| {-# LANGUAGE ExistentialQuantification #-} -- Used for SomeNamed. | |
| {-# LANGUAGE PatternSynonyms #-} -- Used for the Name pattern. | |
| {-# LANGUAGE ViewPatterns #-} -- Used for the Name pattern. | |
| {-# LANGUAGE RankNTypes #-} -- Used for withName. | |
| module Named ( Named, pattern Name, forgetName, withName, someNamed, SomeNamed(..) ) where | |
| -- | Give a generated type-level name to any value. |
This is a small experiment to see whether one can:
- Lex a file efficiently, retaining line/column and indentation information.
- Consuming no or little memory (aside from the input size itself), and
- Still have the flexibility to perform zero-cost operations like folds (counting tokens), doing nothing (a simple pass), or printing. SAX-style.
This proves that one could, e.g., run in ST and write to a mutable Storable vector. Allowing the caller to process the set of tokens later. But the cost/calculation of figuring out line/col/indentation of each token has already been figured out.
The input file is war-and-peace.txt which is 6MB. Simply reading the file takes 27ms. Counting all words (non-space) in the file takes 36ms. So let's say about 9ms, in the absense of more rigorous gauge-based benchmarking. There are 1,132,619 "words" in the file.
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 GADTs, LambdaCase #-} | |
| import Control.Monad | |
| -- Model the problem with a simple GADT: | |
| data Foo a where | |
| GetInput :: Foo String | |
| WriteOutput :: String -> Foo () | |
| Pure :: a -> Foo a |
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
| {-# OPTIONS_GHC -fno-warn-type-defaults #-} | |
| {-# LANGUAGE TypeFamilies #-} | |
| {-# LANGUAGE GADTs #-} | |
| {-# LANGUAGE ExtendedDefaultRules #-} | |
| {-# LANGUAGE LambdaCase #-} | |
| {-# LANGUAGE OverloadedStrings #-} | |
| {-# LANGUAGE TypeApplications #-} | |
| {-# LANGUAGE TypeOperators #-} | |
| {-# LANGUAGE ScopedTypeVariables #-} | |
| {-# LANGUAGE StandaloneDeriving #-} |
Change the mx.chrisdone.com mentions to your own domain.
Spin up a Droplet on DigitalOcean with docker-machine.
$ time docker-machine create \
--driver digitalocean \
--digitalocean-access-token $(cat ~/.do-token) \
--digitalocean-monitoring \
--digitalocean-region "lon1" \
--digitalocean-size "s-1vcpu-1gb" \
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
| -- | A currency-less integral monetary value which cannot be further | |
| -- subdivided. E.g. cent, penny, satoshi. | |
| -- | |
| -- For lack of a better name: | |
| -- <https://money.stackexchange.com/questions/85562/generic-name-for-the-smallest-unit-of-currency> | |
| newtype IntegralMoney = IntegralMoney Int | |
| deriving (Eq, Ord, Integral, Num, Enum, Real, Show) | |
| instance PersistFieldSql IntegralMoney where | |
| sqlType _ = SqlString | |
| instance PersistField IntegralMoney where |
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 CPP #-} | |
| -- | | |
| module Data.FileEmbed2 | |
| ( makeRelativeToProject2 | |
| , module Data.FileEmbed | |
| ) where | |
| import Data.FileEmbed | |
| import Language.Haskell.TH |
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 FlexibleContexts #-} | |
| {-# LANGUAGE ExistentialQuantification #-} | |
| {-# LANGUAGE LambdaCase #-} | |
| {-# LANGUAGE GADTs #-} | |
| -- | A restricted web type. | |
| module Web | |
| ( Web(..) | |
| , runWebHandler |
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 BangPatterns #-} | |
| import Control.DeepSeq | |
| import Data.List hiding (foldl) | |
| import Prelude hiding (foldl) | |
| foldl = \f accumulator list -> | |
| case list of | |
| [] -> accumulator | |
| x:xs -> foldlS f (f accumulator x) xs |