Skip to content

Instantly share code, notes, and snippets.

@echatav
Last active January 27, 2018 00:11
Show Gist options
  • Save echatav/362fac156c779a7fbac36eb2080fc047 to your computer and use it in GitHub Desktop.
Save echatav/362fac156c779a7fbac36eb2080fc047 to your computer and use it in GitHub Desktop.
{-# LANGUAGE ExistentialQuantification #-}
import Prelude hiding (id,(.))
import Control.Category
data Learn a b
= forall p. Learn
{ impl :: p -> a -> b
, update :: p -> a -> b -> p
, request :: p -> a -> b -> a
}
instance Category Learn where
id = Learn
{ impl = \ _ a -> a
, update = \ _ _ _ -> ()
, request = \ _ a _ -> a
}
Learn j v s . Learn i u r = Learn
{ impl = \ (p, q) a -> j q (i p a)
, update = \ (p, q) a c ->
( u p a (s q (i p a) c)
, v q (i p a) c
)
, request = \ (p, q) a c -> r p a (s q (i p a) c)
}
data Para a b = forall p. Para (p -> a -> b)
instance Category Para where
id = Para (\ _ a -> a)
Para j . Para i = Para (\ (p, q) a -> j q (i p a))
learn :: Para a b -> Learn a b
learn (Para i) = Learn
{ impl = i
, update = undefined
, request = undefined
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment