Skip to content

Instantly share code, notes, and snippets.

@ferranpujolcamins
ferranpujolcamins / existential.rs
Created November 23, 2021 12:07
A Rust implementation of data Ext b = forall a. Ext a (a -> b)
struct ExistsPrivate<A, F, B>
where F: Fn(&A) -> B {
a: A,
f: F
}
trait AnyExistsPrivate<B> {
fn extract(&self) -> B;
}
@sellout
sellout / metamorphism.hs
Last active January 3, 2023 16:06
Trying to generalize [metamorphisms](http://www.cs.ox.ac.uk/jeremy.gibbons/publications/metamorphisms-scp.pdf) away from lists.
-- | A “flushing” 'stream', with an additional coalgebra for flushing the
-- remaining values after the input has been consumed. This also allows us to
-- generalize the output away from lists.
fstream
:: (Cursive t (XNor a), Cursive u f, Corecursive u f, Traversable f)
=> Coalgebra f b -> (b -> a -> b) -> Coalgebra f b -> b -> t -> u
fstream ψ g ψ' = go
where
go c x =
let fb = ψ c
@mbbx6spp
mbbx6spp / .gitignore
Last active July 15, 2016 22:49
Scalaz-stream code snippet inspired by 'Gender and Language: Fuck as a metaphor for male sexual aggression' (by Pamela Hobbs) - http://home.earthlink.net/~p37954/sitebuildercontent/sitebuilderfiles/Fuck.pdf
target

Hi, looking for scalac flags?

This gist has been upgraded to a blog post here.

@nuttycom
nuttycom / gist:6800642
Created October 2, 2013 21:15
Monad for the right side of Either.
trait Monad[M[_]] {
def pure[A](a: A): M[A]
def flatMap[A, B](f: A => M[B]): M[A] => M[B]
def map[A, B](f: A => B): M[A] => M[B] = flatMap(a => pure(f(a)))
}
class EitherRightMonad[L] extends Monad[({type M[R] = Either[L, R]})#M] {
def pure[A](a: A): Either[L, A] = error("todo")
def flatMap[A, B](f: A => Either[L, B]): Either[L, A] => Either[L, B] = error("todo")
}
@tpolecat
tpolecat / gist:5633028
Last active December 17, 2015 15:39
Ideas re: IO and Future
// Some thoughts on IO and Futures
object Future {
// A future must have the option of performing IO during its computation; this
// is one of the primary uses of Futures. So we construct with an IO[A]. Construction
// is itself an effect because it forks execution of `a`.
def ioFuture[A](a: IO[A]): IO[Future[A]]
// Unit, but it has to be eager, so not super useful. What if it's not really a monad at all?
@nuttycom
nuttycom / gist:3177071
Created July 25, 2012 16:25
Identity Monad
trait Monad[M[_]] {
def pure[A](a: A): M[A]
def flatMap[A, B](f: A => M[B]): M[A] => M[B]
def map[A, B](f: A => B): M[A] => M[B] = flatMap(a => pure(f(a)))
}
object Id {
type Id[X] = X
implicit val M: Monad[Id] = sys.error("todo")
@nuttycom
nuttycom / gist:1037030
Created June 21, 2011 01:21
Reader monad
trait Monad[M[_]] {
def pure[A](a: A): M[A]
def flatMap[A, B](f: A => M[B]): M[A] => M[B]
def map[A, B](f: A => B): M[A] => M[B] = flatMap(a => pure(f(a)))
}
class Reader[I] extends Monad[({type M[O] = Function1[I, O]})#M] {
def pure[A](a: A): Function1[I, A] = error("todo")
def flatMap[A, B](f: A => Function1[I, B]): Function1[I, A] => Function1[I, B] = error("todo")
}