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
@ def id[A](x: A): A = x | |
defined function id | |
@ def k[A, B](x: A, y: B): A = x | |
defined function k | |
@ def a[A, B](f: A => B, x: A): B = f(x) | |
defined function a | |
@ a((x: Int) => x + 1, 1) |
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 | |
class Profunctor p where | |
dimap :: (a -> b) -> (c -> d) -> p b c -> p a d | |
-- lmap :: (a -> b) -> p b c -> p a c | |
-- rmap :: (c -> d) -> p b c -> p b d | |
instance Profunctor (->) where | |
-- dimap :: (a -> b) -> (c -> d) -> (->) b c -> (->) a d |
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
class Contravariant f where | |
fmap :: (b -> a) -> f a -> f b | |
newtype Predicate a = Predicate { runPredicate :: a -> Bool } | |
instance Contravariant Predicate where | |
fmap f (Predicate a) = Predicate (a . f) | |
data MyOrdering = LT | EQ | GT |
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
scala> "{ /* hello */ def foo(bar: Int) = bar }".parse[Term].get | |
res0: scala.meta.Term = { /* hello */ def foo(bar: Int) = bar } | |
scala> res0 transform { case q"bar" => q"baz" } | |
x.origin: Parsed(Input.String("{ /* hello */ def foo(bar: Int) = bar }"),Scala211,[18..21) in Input.String("{ /* hello */ def foo(bar: Int) = bar }")) | |
x : foo | |
x.origin: Transformed(bar) | |
x : baz |
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
scala> type Foo[A, B] = Map[A, B] | |
defined type alias Foo | |
scala> type World[M[_]] = M[Int] | |
warning: there was one feature warning; re-run with -feature for details | |
defined type alias World | |
scala> type X[A] = World[({ type M[A] = Foo[String, A] })#M] | |
defined type alias X |
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 RankNTypes #-} | |
module F where | |
data User = User { name :: String, age :: Int } deriving Show | |
data Project = Project { owner :: User } deriving Show | |
type Lens s a = Functor f => (a -> f a) -> s -> f s | |
newtype Identity a = Identity { runIdentity :: 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
data Toy b next = | |
Output b next | |
| Bell next | |
| Done | |
deriving (Show) | |
data FixE f e = Fix (f (FixE f e)) | Throw e | |
catch :: (Functor f) => FixE f e1 -> (e1 -> FixE f e2) -> FixE f e2 | |
catch (Fix x) f = Fix (fmap (flip catch f) x) |
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
trait Vect[Size, A] | |
def ++[n, m, a](v1: Vect[n, a], v2: Vect[m, a]): Vect[(n + m), 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
sequence :: Monad m => [m a] -> m [a] | |
sequence = foldr mcons (return []) | |
where mcons p q = p >>= \x -> q >>= \y -> return (x : y) | |
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
{- ---------------------------------------------------------------------- | |
Raw code file for "Evolution of a Haskell Programmer" | |
Fritz Ruehr, Willamette University | |
See <http://www.willamette.edu/~fruehr/haskell/evolution.html> | |
Any given variation section (seperated by horizontal rules) can be enabled | |
by setting off its delimiting nested comments with EOL comments | |
(in which case the previously enabled section should be disabled). |
NewerOlder