compiling-to-categories / concat

Compiling to Categories
http://conal.net/papers/compiling-to-categories
BSD 3-Clause "New" or "Revised" License
431 stars 49 forks source link

Deduplicate LoopCat and TracedCat #95

Open sellout opened 2 years ago

sellout commented 2 years ago

It was pointed out on the FP slack that both of these classes exist in ConCat.Category, but are defined identically.

It seems like either the difference should be documented or one should be removed. Considering that the implementation of TracedCat (->) is the same as ArrowLoop (->), I'm assuming they're actually the same, in which case the preferred name just needs to be decided. I'm partial to TracedCat, as it's from CT and has better implementations already, but LoopCat matches the Haskell naming (ArrowLoop) and, judging by them being added in the same commit, perhaps has some relationship to DelayCat?

There's also a missing TracedCat (Constrained con k) instance which should be added.

I'm happy to do the work once I know which name is preferred.

freckletonj commented 2 years ago

Cool connection. @lyxia offered section 5.1 of this paper for details on the connection.

DelayCat is necessary to make looping work for streaming-type arrows (Streams, MonadicStreamFunctions, Yampa). The reason is that for a stream to loop it (always?) relies on laziness in the looped value, and on the first iteration, when this undefined recursive variable is forced, what value should it have? It'll be an infinite loop unless you use delay to provide that first value.

As far as names, I tend to aesthetically prefer the Cartesian, Monoidal, etc world of names, because it helps one connect to the CT better, which would suggest Traced is the right choice. But my impression is that this library is tending toward ProductCat etc to use names that are more immediately apparent, which would suggest Loop. I'm not particularly partial between the two options though. The only relevant bike-shedding I'd propose is to move from ProductCat et al to just Product, because if it's already namespaced under Category it's obvious it's a Cat.

mikesperber commented 2 years ago

I'm all for TracedCat. (I like the Cat to be uniform with the type classes that have a non-Cat counterpart such as Functor.)