Skip to content

Instantly share code, notes, and snippets.

View akhileshs's full-sized avatar

Akhilesh Srikanth akhileshs

  • San Francisco, CA
View GitHub Profile
@ 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)
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
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
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
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
{-# 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 }
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)
trait Vect[Size, A]
def ++[n, m, a](v1: Vect[n, a], v2: Vect[m, a]): Vect[(n + m), a]
sequence :: Monad m => [m a] -> m [a]
sequence = foldr mcons (return [])
where mcons p q = p >>= \x -> q >>= \y -> return (x : y)
{- ----------------------------------------------------------------------
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).