Skip to content

Instantly share code, notes, and snippets.

Akhilesh Srikanth akhileshs

  • San Francisco, CA
Block or report user

Report or block akhileshs

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View combinator.scala
@ 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)
View profunctor.hs
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
View contravariant.hs
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
View t1.scala
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
View trialtypelambdas.scala
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
View trial1.hs
{-# 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 }
View free_monad.hs
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)
View dt.scala
trait Vect[Size, A]
def ++[n, m, a](v1: Vect[n, a], v2: Vect[m, a]): Vect[(n + m), a]
View sequence.hs
sequence :: Monad m => [m a] -> m [a]
sequence = foldr mcons (return [])
where mcons p q = p >>= \x -> q >>= \y -> return (x : y)
View evolution.hs
{- ----------------------------------------------------------------------
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).
You can’t perform that action at this time.