You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment, row types are lists of the same type. This is not necessary at all and may be providing too much flexibility and too little at the same time:
The type does not encode the width of the data. Sometimes this is helpful as the number of columns can be dynamic but often this is not required.
Different columns may have different types that are an instance of Cell.
It turns out that this can be solved with little effort:
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE FlexibleInstances #-}
importData.FoldableclassCellawherebuildCell::a->StringnewtypeWrapped=WrappedStringinstanceCellStringwhere
buildCell =idinstanceCellWrappedwhere
buildCell (Wrapped s) = s
dataAnyCell=forallc.Cellc=>AnyCellcclassRowawheretoCellList::a-> [AnyCell]
instance {-# OVERLAPPING #-} (Cella, Cellb) =>Row (a, b) where
toCellList (x, y) = [AnyCell x, AnyCell y]
instance (Cella, Cellb, Cellc) =>Row (a, b, c) where
toCellList (x, y, z) = [AnyCell x, AnyCell y, AnyCell z]
instance {-# OVERLAPPABLE #-} (Foldablef, Cella) =>Row (fa) where
toCellList xs =AnyCell<$> toList xs
str::Rowr=>r->String
str r =unwords$map f $ toCellList r
where
f (AnyCell c) = buildCell c
main::IO()
main =do
test ("foo", Wrapped"bar", "baz")
test (Wrapped"foo", "bar")
test [Wrapped"x", Wrapped"y", Wrapped"z"]
wheretest::forallr.Rowr=>r->IO()
test =putStrLn. str
Alternatively, one could also provide an instance for HList and use instances from tuple-hlist to define those.
The text was updated successfully, but these errors were encountered:
At the moment, row types are lists of the same type. This is not necessary at all and may be providing too much flexibility and too little at the same time:
Cell
.It turns out that this can be solved with little effort:
Alternatively, one could also provide an instance for
HList
and use instances fromtuple-hlist
to define those.The text was updated successfully, but these errors were encountered: