löb is a well-known function in Haskell for implementing spreadsheet-like behaviors and tying the knot. It is defined as:
loeb :: Functor f => f (f a -> a) -> f a
loeb fs = xs
where xs = fmap ($ xs) fs
löb is a well-known function in Haskell for implementing spreadsheet-like behaviors and tying the knot. It is defined as:
loeb :: Functor f => f (f a -> a) -> f a
loeb fs = xs
where xs = fmap ($ xs) fs
Sometimes it would be nice if a type system could automatically "do it's best" | |
to restrict what a value will be. For example, the type `Bool` is the compiler | |
saying the value will either be `True` or `False`, but it doesn't know which. | |
What we want is the compiler to be able to be precise when possible, so instead | |
of always saying `Bool` (or "I don't know"), it could say `True`, `False`, or | |
`Bool`. This gist shows how Hindley Milner already has this capability that can | |
be exercised by using Church or Scott encodings of simple data types. | |
> {-# LANGUAGE RankNTypes #-} | |
> import qualified Data.Maybe as M |
{-# LANGUAGE DeriveFunctor #-} | |
{-# LANGUAGE StandaloneDeriving #-} | |
{-# LANGUAGE DeriveFoldable #-} | |
{-# LANGUAGE DeriveTraversable #-} | |
import Prelude hiding (take) | |
import Control.Comonad | |
import Control.Comonad.Sheet | |
import Data.Foldable | |
import Data.Traversable |
#!/bin/bash -eu | |
LOG_FILE=$1 | |
SB="stdbuf -i0 -oL" | |
shift | |
tput sc | |
$@ 2>&1 | $SB tee $LOG_FILE | $SB cut -c-$(tput cols) | $SB sed -u 's/\(.\)/\\\1/g' | $SB xargs -0 -d'\n' -iyosi -n1 bash -c 'tput rc;tput el; printf "\r%s" yosi' | |
EXIT_CODE=${PIPESTATUS[0]} | |
tput rc;tput el;printf "\r" # Delete the last printed line | |
exit $EXIT_CODE |
{-# LANGUAGE DataKinds, KindSignatures, GADTs, StandaloneDeriving, TypeFamilies #-} | |
module Bidirectional where | |
import Control.Applicative | |
import Control.Monad (when) | |
---------------------------------------- | |
-- 'Flow d a' is like 'Maybe a' except the type index 'd' says whether | |
-- we're given a value or whether we want one. |
{-# LANGUAGE DeriveDataTypeable, GeneralizedNewtypeDeriving, TemplateHaskell, FlexibleInstances #-} | |
{-# OPTIONS_GHC -Wall -fno-warn-missing-signatures #-} | |
module QQAST where | |
import Control.Applicative | |
import Control.Exception | |
import Control.Monad.State | |
import Data.Data (Data) | |
import Data.Generics (extQ) | |
import Data.IORef |
type re = C of char | Nil | Seq of re * re | Bot | Alt of re * re | Star of re | |
let rec null = function | |
| C _ | Bot -> false | |
| Nil | Star _ -> true | |
| Alt(r1, r2) -> null r1 || null r2 | |
| Seq(r1, r2) -> null r1 && null r2 | |
module R = Set.Make(struct type t = re let compare = compare end) | |
let rmap f rs = R.fold (fun r -> R.add (f r)) rs R.empty |
module DoubleCont where | |
import Control.Monad.Cont | |
reset :: ContT a (ContT r m) a -> ContT b (ContT r m) a | |
reset e = ContT $ \k -> | |
ContT $ \m -> | |
runContT (runContT e return) | |
(\r -> runContT (k r) m) |
(def s {:l {:l {:val 4} | |
:r {:val 6} | |
:val 10} | |
:r {:val 20 | |
:l {:val 11 | |
:l {:val 3} | |
:r {:val 8}} | |
:r {:val 9 | |
:l {:val 2} | |
:r {:val 7}}} |