mirror of
https://github.com/byteverse/colonnade.git
synced 2026-04-18 22:24:23 +02:00
begin making Colonnade a Profunctor, not compiling
This commit is contained in:
parent
d93b369f19
commit
9a14ce158a
@ -37,6 +37,7 @@ library
|
|||||||
, vector >= 0.10 && < 0.13
|
, vector >= 0.10 && < 0.13
|
||||||
, text >= 1.0 && < 1.3
|
, text >= 1.0 && < 1.3
|
||||||
, bytestring >= 0.10 && < 0.11
|
, bytestring >= 0.10 && < 0.11
|
||||||
|
, profunctors >= 4.0 && < 5.3
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
ghc-options: -Wall
|
ghc-options: -Wall
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import Data.Functor.Contravariant (Contravariant(..))
|
|||||||
import Data.Functor.Contravariant.Divisible (Divisible(..))
|
import Data.Functor.Contravariant.Divisible (Divisible(..))
|
||||||
import Control.Exception (Exception)
|
import Control.Exception (Exception)
|
||||||
import Data.Typeable (Typeable)
|
import Data.Typeable (Typeable)
|
||||||
|
import Data.Profunctor (Profunctor(..))
|
||||||
import qualified Data.Vector as Vector
|
import qualified Data.Vector as Vector
|
||||||
|
|
||||||
-- | As the first argument to the 'Colonnade' type
|
-- | As the first argument to the 'Colonnade' type
|
||||||
@ -46,13 +47,14 @@ instance Contravariant Headless where
|
|||||||
contramap _ Headless = Headless
|
contramap _ Headless = Headless
|
||||||
|
|
||||||
-- | Encodes a header and a cell.
|
-- | Encodes a header and a cell.
|
||||||
data OneColonnade h content a = OneColonnade
|
data OneColonnade h a c = OneColonnade
|
||||||
{ oneColonnadeHead :: !(h content)
|
{ oneColonnadeHead :: !(h c)
|
||||||
, oneColonnadeEncode :: !(a -> content)
|
, oneColonnadeEncode :: !(a -> c)
|
||||||
}
|
} deriving (Functor)
|
||||||
|
|
||||||
instance Contravariant (OneColonnade h content) where
|
instance Functor h => Profunctor (OneColonnade h) where
|
||||||
contramap f (OneColonnade h e) = OneColonnade h (e . f)
|
rmap = fmap
|
||||||
|
lmap f (OneColonnade h e) = OneColonnade h (e . f)
|
||||||
|
|
||||||
-- | An columnar encoding of @a@. The type variable @h@ determines what
|
-- | An columnar encoding of @a@. The type variable @h@ determines what
|
||||||
-- is present in each column in the header row. It is typically instantiated
|
-- 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
|
-- 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
|
-- 'Colonnade's are defined at the top-level so that GHC avoids reconstructing
|
||||||
-- them every time they are used.
|
-- them every time they are used.
|
||||||
newtype Colonnade h c a = Colonnade
|
newtype Colonnade h a c = Colonnade
|
||||||
{ getColonnade :: Vector (OneColonnade h c a)
|
{ getColonnade :: Vector (OneColonnade h a c)
|
||||||
} deriving (Monoid)
|
} deriving (Monoid,Functor)
|
||||||
|
|
||||||
instance Contravariant (Colonnade h content) where
|
instance Functor h => Profunctor (Colonnade h) where
|
||||||
contramap f (Colonnade v) = Colonnade
|
rmap = fmap
|
||||||
(Vector.map (contramap f) v)
|
lmap f (Colonnade v) = Colonnade
|
||||||
|
(Vector.map (lmap 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)
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user