Original link: http://www.concentric.net/~Ttwang/tech/inthash.htm
Taken from: http://web.archive.org/web/20071223173210/http://www.concentric.net/~Ttwang/tech/inthash.htm
Reformatted using pandoc
Thomas Wang, Jan 1997
last update Mar 2007
package object mail { | |
implicit def stringToSeq(single: String): Seq[String] = Seq(single) | |
implicit def liftToOption[T](t: T): Option[T] = Some(t) | |
sealed abstract class MailType | |
case object Plain extends MailType | |
case object Rich extends MailType | |
case object MultiPart extends MailType |
Original link: http://www.concentric.net/~Ttwang/tech/inthash.htm
Taken from: http://web.archive.org/web/20071223173210/http://www.concentric.net/~Ttwang/tech/inthash.htm
Reformatted using pandoc
Thomas Wang, Jan 1997
last update Mar 2007
data Zero = Zero | |
data Succ a = Succ a | |
pred = \s -> case s of Succ a -> a | |
meters = \n -> | |
{ multiply: \v -> v { value = n * v.value, meters = Succ (v.meters) } | |
, divide: \v -> v { value = n / v.value, meters = pred (v.meters) } | |
} |
-- | Echo: a small experimental library for functional reactive programming. | |
{-# LANGUAGE | |
GADTs | |
, GeneralizedNewtypeDeriving | |
, TemplateHaskell | |
, RecursiveDo | |
, MagicHash | |
, UnboxedTuples | |
#-} |
-- in reply to http://www.reddit.com/r/haskell/comments/21mja6/make_lllegal_state_transitions_unrepresentable/ | |
-- | |
-- We implement a tiny language with three commands: Open, Close, and Get. | |
-- The first Get after an Open returns 1, the second Get returns 2, and so on. | |
-- | |
-- Get is only valid while the state is open, and | |
-- Open must always be matched by a Close. | |
-- We enforce both restrictions via the type system. | |
-- | |
-- There are two valid states: Opened and Closed. |
sealed trait Interact[A] | |
case class Ask(prompt: String) | |
extends Interact[String] | |
case class Tell(msg: String) | |
extends Interact[Unit] | |
trait Monad[M[_]] { | |
def pure[A](a: A): M[A] |
This is material to go along with a 2014 Boston Haskell talk.
We are going to look at a series of type signatures in Haskell and explore how parametricity (or lack thereof) lets us constrain what a function is allowed to do.
Let's start with a decidedly non-generic function signature. What are the possible implementations of this function which typecheck?
wrangle :: Int -> Int
package com.rr.experiment | |
import org.specs2.ScalaCheck | |
import org.specs2.mutable._ | |
import org.scalacheck._ | |
import scalaz._ | |
import scodec._ |
test = map ((*) 2) >>> filter ((>) 15) >>> drop 3 >>> map show | |
src1 = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] | |
src2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
res1 = transduce' test src1 :: [String] | |
res2 = transduce' test src2 :: List String |
-- A port of: http://semantic-domain.blogspot.com/2015/03/abstract-binding-trees.html | |
{-# LANGUAGE DeriveFunctor #-} | |
module ABT where | |
import qualified Data.Foldable as Foldable | |
import Data.Foldable (Foldable) | |
import Data.Set (Set) | |
import qualified Data.Set as Set |