Skip to content

Instantly share code, notes, and snippets.

@YoEight
YoEight / Conversion.scala
Last active December 19, 2015 18:48
Scalaz-stream Process to Play Enumerator
package deiko
import scala.concurrent.Future
import scala.concurrent.duration.Duration
import scalaz.concurrent.Task
import scalaz.stream._
import play.api.libs.iteratee._
import Process._
object Conversion {
@YoEight
YoEight / Foo-error.hs
Last active December 19, 2015 23:49
Why Foo-error.hs doesn't compile while Foo-working.hs does ?
{-# LANGUAGE RankNTypes #-}
type Foo = forall m. Monad m => Int -> m Int
data Free f a = Pure a
| Free (f (Free f a))
data Instr a = Instr Int a
instance Functor Instr where
@YoEight
YoEight / output
Last active December 26, 2015 16:39
GHC (7.6.3) GADTs bug ? Output is GHC output when GADTs is enabled
ghc -Wall -ferror-spans -fforce-recomp -c /home/yorick/Desktop/process.hs
/home/yorick/Desktop/process.hs:34:9-34:
Couldn't match type `a1' with `a2'
because type variable `a2' would escape its scope
This (rigid, skolem) type variable is bound by
a type expected by the context:
m a2 -> (a2 -> Process m a) -> Process m a -> r
The following variables have types that mention a1
awaiting :: m a1 -> (a1 -> Process m a) -> Process m a -> r
@YoEight
YoEight / Exo.scala
Created November 27, 2013 13:13
Mu exercise (Scala 2.10)
import scala.language.higherKinds
trait Functor[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
}
object Functor {
def apply[F[_], A, B](fa: F[A])(f: A => B)(implicit F: Functor[F]): F[B] =
F.map(fa)(f)
}
@YoEight
YoEight / proc.scala
Last active December 31, 2015 22:09
scalaz.Process and Free equiv. using simple structure encoding
sealed trait Free[F[_], A]
case class Return[F[_], A](v: A) extends Free[F, A]
case class Suspend[F[_], A](s: F[Free[F, A]]) extends Free[F, A]
sealed trait ProcessB[T[_], O, B]
case class Emit[T[_], O, B](o: O, next: B) extends ProcessB[T, O, B]
case class Await[T[_], A, O, B](ta: T[A], k: A => B) extends ProcessB[T, O, B]
case class Stop[T[_], O, B] extends ProcessB[T, O, B]
type Process[T[_], O] = Free[({ type F[x] = ProcessB[T,O,x] })#F, O]
@YoEight
YoEight / recursion.hs
Created December 23, 2013 22:57
Recursion scheme playground
{-# LANGUAGE NoImplicitPrelude #-}
module Origami where
import Prelude
(
(.)
, (-)
, (*)
, (++)
, ($)
From d8730a5b72f263754e82c5e18ee53abf0c002b46 Mon Sep 17 00:00:00 2001
From: YoEight <[email protected]>
Date: Sat, 11 Jan 2014 13:30:23 +0100
Subject: [PATCH] Apply changes relative to TH.Pred becoming a TH.Type's
synonym (issue #7021)
---
compiler/deSugar/DsMeta.hs | 53 +++++++++++++++++++----------------------
compiler/hsSyn/Convert.lhs | 16 +++++--------
compiler/typecheck/TcSplice.lhs | 41 +++++++++++++++++++++++--------
@YoEight
YoEight / gist:8773962
Created February 2, 2014 20:02
I'm doing something wrong
Sun Feb 2 20:44 2014 Time and Allocation Profiling Report (Final)
spellcheck +RTS -p -sstderr -RTS
total time = 0.00 secs (0 ticks @ 1000 us, 1 processor)
total alloc = 90,424 bytes (excludes profiling overheads)
COST CENTRE MODULE %time %alloc
CAF GHC.IO.Handle.FD 0.0 38.4
@YoEight
YoEight / process.hs
Created February 9, 2014 18:47
Possible Process Haskell impl.
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GADTs #-}
module Data.Process where
import Prelude hiding (zipWith)
import Control.Applicative
import Control.Monad
import Data.Foldable
@YoEight
YoEight / Code.hs
Created February 27, 2014 20:54
My answer to http://codepad.org/McxPLp1l exercise
import Data.Functor.Foldable
divIfMultiple :: Integral a => a -> [a] -> Maybe [a]
divIfMultiple x = cata go
where
go Nil = Just []
go (Cons a r)
| mod a x == 0 = fmap (div a x:) r
| otherwise = Nothing