Closed shdpl closed 6 years ago
Let's consider the general type of S.ap
:
ap :: Apply f => f (a -> b) -> f a -> f b
We could replace Apply f => f
with StrMap
, giving:
ap :: StrMap (a -> b) -> StrMap a -> StrMap b
Here's an example of this type in use:
> S.ap ({x: Math.sqrt, y: S.add (1), z: S.sub (1)}) ({w: 4, x: 4, y: 4})
{x: 2, y: 5}
{list: [1,2,3], obj: {}}
, though, is not a string map: its values are of different types. It is a record:
{list: [1,2,3], obj: {}} :: { list :: Array Number, obj: {} }, { list :: Array Number, obj :: StrMap Boolean }, ...
{list: [1,2,3], obj: {}}
is a member of infinitely many record types due to the polymorphic nature of {}
, but none of these types is compatible with S.ap
.
S.ap
is not intended to work with record types. One could, though, define func
like this:
// func :: { list :: Array a, obj :: b } -> { list :: Array a, obj :: b }
const func = record => ({
list: S.I (record.list),
obj: record.obj,
});
I hope this is helpful, @shdpl. :)
I was hoping for ap (a) partial determining expected b type by a (as it doesn't need "interface" for all keys, just the ones it's using). I'll fallback to use sanctuary+ramda, or ramda for the time being. Thank you.
I'm trying switch from ramda to sanctuary which seems to be better designed library. I don't know lots of the 'pro' functional semantics, but from my perspective having error like that is not intuitive. Do you treat it as a bug, or you enforce object values to be typed the same?