Skip to content

Commit

Permalink
Cleanup functional dependencies and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
natefaubion committed Oct 21, 2018
1 parent b61734d commit 0ba771a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions src/Heterogeneous/Folding.purs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ class Folding f x y z | f x y -> z where
instance functionFolding :: Folding (x -> y -> x) x y x where
folding f = f

class FoldingWithIndex f i x y z | f x y -> z, f -> i where
class FoldingWithIndex f i x y z | f i x y -> z where
foldingWithIndex :: f -> i -> x -> y -> z

instance functionFoldingWithIndex :: FoldingWithIndex (i -> x -> y -> x) i x y x where
foldingWithIndex f = f

class HFoldl f x a b | f a -> x b where
class HFoldl f x a b | f x a -> b where
hfoldl :: f -> x -> a -> b

class HFoldlWithIndex f x a b | f a -> x b where
class HFoldlWithIndex f x a b | f x a -> b where
hfoldlWithIndex :: f -> x -> a -> b

newtype ConstFolding f = ConstFolding f
Expand Down Expand Up @@ -106,7 +106,7 @@ instance hfoldlRecordWithIndex ::
hfoldlWithIndex f x =
foldlRecordRowList f x (RLProxy :: RLProxy rl)

class FoldlRecord f x (rl :: RowList) (r :: # Type) b | rl -> f x r b where
class FoldlRecord f x (rl :: RowList) (r :: # Type) b | f x rl -> b, rl -> r where
foldlRecordRowList :: f -> x -> RLProxy rl -> { | r } -> b

instance foldlRecordCons ::
Expand Down Expand Up @@ -166,7 +166,7 @@ instance hfoldlVariantWithIndex ::
hfoldlWithIndex =
foldlVariantRowList (RLProxy :: RLProxy rl)

class FoldlVariant f x (rl :: RowList) (r :: # Type) b | rl -> f x r b where
class FoldlVariant f x (rl :: RowList) (r :: # Type) b | f x rl -> b, rl -> r where
foldlVariantRowList :: RLProxy rl -> f -> x -> Variant r -> b

instance foldlVariantCons ::
Expand Down Expand Up @@ -204,7 +204,7 @@ instance hfoldlVariantFWithIndex ::
hfoldlWithIndex =
foldlVariantFRowList (RLProxy :: RLProxy rl)

class FoldlVariantF f x (rl :: RowList) (r :: # Type) z y | rl -> f x r z y where
class FoldlVariantF f x (rl :: RowList) (r :: # Type) z y | f x rl z -> r y where
foldlVariantFRowList :: RLProxy rl -> f -> x -> VariantF r z -> y

instance foldlVariantFCons ::
Expand Down
8 changes: 4 additions & 4 deletions src/Heterogeneous/Mapping.purs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Type.Row (RLProxy(..))
class Mapping f a b | f a -> b where
mapping :: f -> a -> b

class MappingWithIndex f i a b | f a -> b, f -> i where
class MappingWithIndex f i a b | f i a -> b where
mappingWithIndex :: f -> i -> a -> b

instance mappingFunction :: Mapping (a -> b) a b where
Expand Down Expand Up @@ -80,7 +80,7 @@ instance hmapWithIndexRecord ::
Builder.build
<<< mapRecordWithIndexBuilder (RLProxy :: RLProxy rl)

class MapRecordWithIndex (xs :: RowList) f (as :: # Type) (bs :: # Type) | xs -> f as bs where
class MapRecordWithIndex (xs :: RowList) f (as :: # Type) (bs :: # Type) | xs f -> bs, xs -> as where
mapRecordWithIndexBuilder :: RLProxy xs -> f -> Builder { | as } { | bs }

instance mapRecordWithIndexCons ::
Expand Down Expand Up @@ -138,7 +138,7 @@ instance hmapWithIndexVariant ::
hmapWithIndex =
mapVariantWithIndex (RLProxy :: RLProxy rl)

class MapVariantWithIndex (xs :: RowList) f (as :: # Type) (bs :: # Type) | xs -> f as bs where
class MapVariantWithIndex (xs :: RowList) f (as :: # Type) (bs :: # Type) | xs f -> bs, xs -> as where
mapVariantWithIndex :: RLProxy xs -> f -> Variant as -> Variant bs

instance mapVariantWithIndexCons ::
Expand Down Expand Up @@ -177,7 +177,7 @@ instance hmapWithIndexVariantF ::
hmapWithIndex =
mapVariantFWithIndex (RLProxy :: RLProxy rl)

class MapVariantFWithIndex (xs :: RowList) f (as :: # Type) (bs :: # Type) x y | xs -> f as bs x y where
class MapVariantFWithIndex (xs :: RowList) f (as :: # Type) (bs :: # Type) x y | xs f x -> as bs y where
mapVariantFWithIndex :: RLProxy xs -> f -> VariantF as x -> VariantF bs y

instance mapVariantFWithIndexCons ::
Expand Down
2 changes: 1 addition & 1 deletion test/HList.purs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ showWithIndex :: forall hlist.
hlist ->
Array (Tuple Int String)
showWithIndex =
hfoldlWithIndex ShowWithIndex []
hfoldlWithIndex ShowWithIndex ([] :: Array (Tuple Int String))

testShow :: _
testShow =
Expand Down
28 changes: 14 additions & 14 deletions test/Record.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import Data.Maybe (Maybe(..))
import Data.Symbol (class IsSymbol, SProxy, reflectSymbol)
import Data.Tuple (Tuple(..))
import Heterogeneous.Folding (class Folding, class FoldingWithIndex, class HFoldl, class HFoldlWithIndex, hfoldl, hfoldlWithIndex)
import Heterogeneous.Mapping (class HMapWithIndex, class MapRecordWithIndex, class Mapping, class MappingWithIndex, hmap, hmapWithIndex, mapping)
import Heterogeneous.Mapping (class HMapWithIndex, class Mapping, class MappingWithIndex, hmap, hmapWithIndex, mapping)
import Prim.Row as Row
import Prim.RowList (class RowToList)
import Record as Record
import Record.Builder (Builder)
import Record.Builder as Builder
Expand Down Expand Up @@ -132,13 +131,13 @@ instance traverseProp ::

traverseRecord :: forall f k rin rout.
Applicative f =>
HFoldlWithIndex (TraverseProp f k) (f (Builder {} {})) { | rin } (f (Builder {} { | rout})) =>
HFoldlWithIndex (TraverseProp f k) (f (Builder {} {})) { | rin } (f (Builder {} { | rout })) =>
k ->
{ | rin } ->
f { | rout }
traverseRecord k =
map (flip Builder.build {}) <<<
hfoldlWithIndex (TraverseProp k :: TraverseProp f k) (pure identity)
map (flip Builder.build {})
<<< hfoldlWithIndex (TraverseProp k :: TraverseProp f k) (pure identity :: f (Builder {} {}))

test1 :: _
test1 =
Expand Down Expand Up @@ -188,7 +187,8 @@ sequencePropsOf :: forall f rin rout.
{ | rin } ->
f { | rout }
sequencePropsOf =
map (flip Builder.build {}) <<< hfoldlWithIndex (SequencePropOf :: SequencePropOf f) (pure identity)
map (flip Builder.build {})
<<< hfoldlWithIndex (SequencePropOf :: SequencePropOf f) (pure identity :: f (Builder {} {}))

test :: Maybe _
test =
Expand All @@ -211,7 +211,7 @@ instance replaceLeftH ::
replaceLeft :: forall rvals rin rout.
HMapWithIndex (ReplaceLeft rvals) { | rin } { | rout } =>
{ | rvals } ->
{ | rin } ->
{ | rin } ->
{ | rout }
replaceLeft =
hmapWithIndex <<< ReplaceLeft
Expand All @@ -236,7 +236,7 @@ instance replaceRightH ::
replaceRight :: forall rvals rin rout.
HMapWithIndex (ReplaceRight rvals) { | rin } { | rout } =>
{ | rvals } ->
{ | rin } ->
{ | rin } ->
{ | rout }
replaceRight =
hmapWithIndex <<< ReplaceRight
Expand All @@ -251,15 +251,15 @@ testReplaceRight =
, b: Right 1
}

testReplaceBoth :: forall rvals rin rout rs.
RowToList rout rs =>
HMapWithIndex (ReplaceLeft rvals) { | rin } { | rout } =>
HMapWithIndex (ReplaceRight rvals) { | rin } { | rout } =>
MapRecordWithIndex rs (ReplaceRight rvals) rout rout =>
testReplaceBoth :: forall rvals rin rmid rout.
HMapWithIndex (ReplaceLeft rvals) { | rin } { | rmid } =>
HMapWithIndex (ReplaceRight rvals) { | rmid } { | rout } =>
{ | rvals } ->
{ | rin } ->
{ | rout }
testReplaceBoth vals = replaceRight vals <<< replaceLeft vals
testReplaceBoth vals =
(replaceLeft vals :: { | rin } -> { | rmid }) >>>
(replaceRight vals :: { | rmid } -> { | rout })

-----
-- Verify that multiple folds can be used in constraints.
Expand Down

0 comments on commit 0ba771a

Please sign in to comment.