Skip to content

Instantly share code, notes, and snippets.

module Main where
import Control.Monad
data P i o a
= Input (i -> P i o a)
| Output o (P i o a)
| Return a
instance Functor (P i o) where
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE Arrows #-}
{-# LANGUAGE ConstraintKinds #-}
module Task where
import Prelude hiding (id, (.))
trait Eq[A] {
val eq: String
}
trait Ord[A] {
val ord: String
}
implicit val eqInt: Eq[Int]
= new Eq[Int] { val eq = "eqInt"}
implicit val ordInt: Ord[Int]
@rubenpieters
rubenpieters / Main.purs
Created January 10, 2018 20:51
Unsafely Inspecting Monadic Computations
module Main where
import Prelude
import Data.Set as S
import Data.Array
import Data.Lazy
import Data.Maybe
import Data.Tuple
@rubenpieters
rubenpieters / Main.purs
Last active December 7, 2017 12:37
purescript passing impure callbacks
module Main where
import Prelude
import Data.Foreign.EasyFFI
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
-- code for wrapping impure functions
//-------------------------
// Monad Transformer
//-------------------------
import cats.data._
import cats.implicits._
import cats._
type MonadStackStateTEither[ErrorType, StateType, ReturnType] =
StateT[Either[ErrorType, ?], StateType, ReturnType]
class BlockOp(implicit ec: ExecutionContext) {
def blockOp(number: Int) = Future {
Thread.sleep(2000)
println(s"$number after sleep, time is now ${System.currentTimeMillis() / 1000}")
number
}
}
sealed trait TestTraverse[A]
case class BlockingOp(number: Int) extends TestTraverse[Int]