From 9a14ce158a024c7738bc35d7076655746d599c8d Mon Sep 17 00:00:00 2001 From: Andrew Martin Date: Mon, 13 Feb 2017 07:39:25 -0500 Subject: [PATCH] begin making Colonnade a Profunctor, not compiling --- colonnade/colonnade.cabal | 1 + colonnade/src/Colonnade/Internal.hs | 34 +++++++++++++---------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/colonnade/colonnade.cabal b/colonnade/colonnade.cabal index 6f07682..7fdf207 100644 --- a/colonnade/colonnade.cabal +++ b/colonnade/colonnade.cabal @@ -37,6 +37,7 @@ library , vector >= 0.10 && < 0.13 , text >= 1.0 && < 1.3 , bytestring >= 0.10 && < 0.11 + , profunctors >= 4.0 && < 5.3 default-language: Haskell2010 ghc-options: -Wall diff --git a/colonnade/src/Colonnade/Internal.hs b/colonnade/src/Colonnade/Internal.hs index de0f3ad..36c0528 100644 --- a/colonnade/src/Colonnade/Internal.hs +++ b/colonnade/src/Colonnade/Internal.hs @@ -16,6 +16,7 @@ import Data.Functor.Contravariant (Contravariant(..)) import Data.Functor.Contravariant.Divisible (Divisible(..)) import Control.Exception (Exception) import Data.Typeable (Typeable) +import Data.Profunctor (Profunctor(..)) import qualified Data.Vector as Vector -- | As the first argument to the 'Colonnade' type @@ -46,13 +47,14 @@ instance Contravariant Headless where contramap _ Headless = Headless -- | Encodes a header and a cell. -data OneColonnade h content a = OneColonnade - { oneColonnadeHead :: !(h content) - , oneColonnadeEncode :: !(a -> content) - } +data OneColonnade h a c = OneColonnade + { oneColonnadeHead :: !(h c) + , oneColonnadeEncode :: !(a -> c) + } deriving (Functor) -instance Contravariant (OneColonnade h content) where - contramap f (OneColonnade h e) = OneColonnade h (e . f) +instance Functor h => Profunctor (OneColonnade h) where + rmap = fmap + lmap f (OneColonnade h e) = OneColonnade h (e . f) -- | An columnar encoding of @a@. The type variable @h@ determines what -- is present in each column in the header row. It is typically instantiated @@ -81,18 +83,12 @@ instance Contravariant (OneColonnade h content) where -- once and then folding over it many times. It is recommended that -- 'Colonnade's are defined at the top-level so that GHC avoids reconstructing -- them every time they are used. -newtype Colonnade h c a = Colonnade - { getColonnade :: Vector (OneColonnade h c a) - } deriving (Monoid) +newtype Colonnade h a c = Colonnade + { getColonnade :: Vector (OneColonnade h a c) + } deriving (Monoid,Functor) -instance Contravariant (Colonnade h content) where - contramap f (Colonnade v) = Colonnade - (Vector.map (contramap f) v) - -instance Divisible (Colonnade h content) where - conquer = Colonnade Vector.empty - divide f (Colonnade a) (Colonnade b) = - Colonnade $ (Vector.++) - (Vector.map (contramap (fst . f)) a) - (Vector.map (contramap (snd . f)) b) +instance Functor h => Profunctor (Colonnade h) where + rmap = fmap + lmap f (Colonnade v) = Colonnade + (Vector.map (lmap f) v)