snowleopard / build

Build Systems à la Carte
MIT License
247 stars 18 forks source link

Simplify typed tasks #18

Closed snowleopard closed 5 years ago

snowleopard commented 5 years ago

An interesting observation: we can now rewrite the type of Task into

type Task c k = forall f. c f => (forall a. k a -> f a) -> (forall a. k a -> Maybe (f a))

...which looks like a morphism between natural transformations. I'll let category theory enthusiasts explain what this strange creature is doing here.

ndmitchell commented 5 years ago

Much nicer!

snowleopard commented 5 years ago

@ndmitchell Thanks! :) I guess this encoding is not possible in Shake, because the universe of keys is open: you want to let users add new types of keys, and therefore cannot keep them all in one GADT.

ndmitchell commented 5 years ago

Indeed - type families are open, GADTs are not - but GADTs are a nicer solution if they work.

snowleopard commented 5 years ago

I've just realised that the typed version of fetch that I added in this PR is very similar to what Haxl has:

dataFetch :: (DataSource u r, Request r a) => r a -> GenHaxl u a

This means, we can give dataFetch a Fetch type:

type Fetch k f a = k a -> f a

dataFetch :: (DataSource u r, Request r a) => Fetch r (GenHaxl u) a

I think this link is pretty cool. @simonmar has been talking about writing build systems in Haxl, and perhaps we could place Haxl somewhere in our Build Systems à la Carte table?