Skip to content

Instantly share code, notes, and snippets.

@regiskuckaertz
Created February 18, 2018 09:24
Show Gist options
  • Save regiskuckaertz/8792a27490ff90b78f716e5778ffb984 to your computer and use it in GitHub Desktop.
Save regiskuckaertz/8792a27490ff90b78f716e5778ffb984 to your computer and use it in GitHub Desktop.
Instance function not in scope?
module Main where
import Prelude
import Data.Either (Either(..))
import Data.Profunctor (class Profunctor, arr)
import Data.Profunctor.Choice (class Choice)
import Data.Profunctor.Strong (second)
import Data.Tuple (Tuple(..))
-- State transformers
newtype StateTrans s i o = ST (Tuple s i → Tuple s o)
instance stFunctor ∷ Functor (StateTrans s a) where
map f (ST st) = ST $ second f <<< st
instance stProfunctor ∷ Profunctor (StateTrans s) where
dimap f g (ST st) = ST $ second g <<< st <<< second f
instance stChoice ∷ Choice (StateTrans s) where
left (ST f) = ST lf
where
lf (Tuple s (Left a)) = let (Tuple s' b) = f (Tuple s a)
in Tuple s' (Left b)
lf (Tuple s (Right c)) = Tuple s (Right c)
-- Fails to compile with: Unknown value left
right f = arr mirror <<< left f <<< arr mirror
where
mirror Left x = Right x
mirror Right x = Left x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment