ursi / purescript-elmish

this will have its own name eventually
https://github.com/ursi/purescript-package-set
3 stars 0 forks source link

Batched a b -> Batched a ...? #8

Open Quelklef opened 3 years ago

Quelklef commented 3 years ago

Hypothesis:

data Batched a b = Single (a b) | Batch (Array (Batched a b))

can become

data Batched a = Single a | Batched (Array (Batched a))

We made this change and followed the type errors and were able to compile without anything suspicious coming up.

Mysterious...

Runtime behaviour was not tested.

Quelklef commented 1 year ago

Recording this here since it's been a question multiple times: the reason Batched is defined as

data BatchedF f a ≅ Array (f a)

instead of

data BatchedA a ≅ Array a

is because to transform the contained as we need only one map:

map :: forall f. Functor f => (a -> b) -> BatchedF f a -> BatchedF f b

instead of two:

(map >>> map) :: forall f. Functor f => (a -> b) -> BatchedA (f a) -> BatchedA (f b)

That is, it's convenience

ursi commented 1 year ago

What about

data BatchedA a ≅ Array a

and then using Compose for the nested case?