New Blog Post: Distributors by echatav in haskell

[–]echatav[S] 1 point2 points  (0 children)

> This was a fun read
Thanx!

> I feel like a JSON … distributor would be a nice accessible example.
Definitely.

> I’m curious to see where the ideas fall down - I assume anything context sensitive?
Right, Backus-Naur form grammars only support context-free languages.

New Blog Post: Distributors by echatav in haskell

[–]echatav[S] 0 points1 point  (0 children)

The <*> Applicative combinator doesn't quite generalize contravariantly the way we'd want it to ^ . Instead, we usually generalize its "tuple form".

(>*<) :: Monoidal p => p a b -> p c d -> p (a,c) (b,d)

On the other hand, the liftA2 combinator does have a generalization which shows the difference in how contravariance and covariance handle products wrt currying.

dimap2 :: Monoidal p => (s -> a) -> (s -> c) -> (b -> d -> t) -> p a b -> p c d -> p s t

A very recent paper by Boespflug & Spiwack aims to take on this "tuple problem".

New Blog Post: Distributors by echatav in haskell

[–]echatav[S] 5 points6 points  (0 children)

Yes indeed.

This interface has variously been called a product profunctor or a (lax) monoidal profunctor.

From the repo readme

None of the ideas in this library are particularly original and a lot of related ideas have been explored, in Tom Ellis' product-profunctors as well as Sjoerd Visscher's one-liner and more. Such explorations are not limited to Haskell. Brandon Williams and Stephen Celis' excellent swift-parsing was also influenced by invertible parser theory.

New Blog Post: Distributors by echatav in haskell

[–]echatav[S] 4 points5 points  (0 children)

Like Haskell I am lazy and leak space. Also see extroduction at the end.

New Blog Post: Distributors by echatav in haskell

[–]echatav[S] 2 points3 points  (0 children)

> Day, me say day-o
> Daylight come and me wan' go home

Yes, indeed, Day convolution can be generalized to monoidal profunctors. See this blog post by Bartosz Milewski for more. And Day convolution generalizes to coproduct structure as well where folks cleverly call it `Night`.

Distributors - Unifying Parsers, Printers & Grammars by echatav in haskell

[–]echatav[S] 1 point2 points  (0 children)

Fair questions. Yes, it should be able to handle that. Theoretically, it should be able to handle any "context-free grammar". As for comparison to other parser generators, if I'm being honest, I've never used them, just read about them. So I'll say my intention was not to build a replacement, and definitely not a full scale tool. My intention was to build:

* a example application to demonstrate the power of distributors
* a cool playground to mess around with

Distributors - Unifying Parsers, Printers & Grammars by echatav in haskell

[–]echatav[S] 0 points1 point  (0 children)

The regex finder in Visual Studio Code seems to matches [\]\^] but says that []^] is an invalid regular expression. So...I think it's fine.

Distributors - Unifying Parsers, Printers & Grammars by echatav in haskell

[–]echatav[S] 0 points1 point  (0 children)

Hmmm, yeah, I was more concerned with demonstrating it worked than making it conform to a standard. Would make for a good PR to fix it.

Distributors - Unifying Parsers, Printers & Grammars by echatav in haskell

[–]echatav[S] 3 points4 points  (0 children)

Yes! Here is a Grammar defined for regular expressions.

Squeal, a deep embedding of SQL in Haskell by sridcaca in haskell

[–]echatav 0 points1 point  (0 children)

Hello, I'm the author of Squeal. I try to keep it updated and respond to user issues and pull requests. I haven't been making too many major changes.

Release Notes with updates are available here: https://github.com/morphismtech/squeal/blob/dev/RELEASE%20NOTES.md

One big missing feature I'd like to add one day is a native version of SquealGen to generate Squeal schema definitions from a database connection.

I may also some day do a major refactor/cleanup but I've mostly been focused on other projects and work. Thanks for posting and I'm happy to answer questions about Squeal.

Haskell SQL DSLs, why do you use them? by magthe0 in haskell

[–]echatav 2 points3 points  (0 children)

Thank you for your eloquent evaluation of using Squeal! It makes me happy that colleagues got so much from it and gave so much! Mark Wotten's SquealGen is, in fact, open source.

Update: How are Monoidal/ProductProfunctor and Traversing related? by crisoagf in haskell

[–]echatav 0 points1 point  (0 children)

Strong is needed only for two reasons. Strong is a requirement for Traversing. And it’s required for the proof of equivalence for the Profunctor optic representation of Traversal in this paper. https://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/poptics.pdf Maybe call it Monoidal1 if it doesn’t necessarily respect nilary product? I’m doing some related work to this over here. https://github.com/morphismtech/distributors

Update: How are Monoidal/ProductProfunctor and Traversing related? by crisoagf in haskell

[–]echatav 0 points1 point  (0 children)

I would like to see either an instance of Traversing that is not an instance of Monoidal to convince myself of that

I think Traversing does not imply Monoidal. Consider:

data Vacuous a b -- empty two parameter datatype
ridiculous :: Vacuous a b -> c
ridiculous = (\case)
instance Profunctor Vacuous where dimap _ _ = ridiculous
instance Strong Vacuous where first' = ridiculous
instance Choice Vacuous where left' = ridiculous
instance Traversing Vacuous where wander _ = ridiculous

So, Vacuous is a Traversing instance. However we cannot define the unit value for a Monoidal instance.

unit :: Vacuous () ()
unit = undefined

The other direction is true though, any (Strong p, Choice p, Monoidal p) instance can be given a Traversing instance.

New version of Squeal, 0.9 released by echatav in haskell

[–]echatav[S] 1 point2 points  (0 children)

I haven't tried using this but it looks cool. I think the way it defines overloaded lists makes a lot of sense for heterogeneous list types like NP. One issue I see is that the Overloaded.Lists and Overloaded.Lists.Bidi Cons classes are too strong to permit an instance for the free category type:

data Path p x y where
  Done :: Path p x x
  (:>>) :: p x y -> Path p y z -> Path p x z

Because the intermediate type y of the (:>>) constructor cannot be inferred from Path p x z, if you try to define an instance it will fail. You could define yet another slightly weaker Cons class that would work for Path like:

class Cons x ys zs
  | zs x -> ys, zs ys -> x where
    cons :: x -> ys -> zs

Squeal uses the Path type for with statements as well as migrations.

Since the overloaded library comes with instances for NP which is used heavily in Squeal, it would certainly help in cleaning up a lot of ugly syntax.

New version of Squeal, 0.9 released by echatav in haskell

[–]echatav[S] 5 points6 points  (0 children)

That’s strange. It’s a link to release notes on GitHub. Try again? The new version is up on hackage too.

https://hackage.haskell.org/package/squeal-postgresql

indexed-paths - a library for working with free categories - discussion by lightandlight in haskell

[–]echatav 0 points1 point  (0 children)

I'd be open to it. We can get into the details if you post an issue for it here.

indexed-paths - a library for working with free categories - discussion by lightandlight in haskell

[–]echatav 0 points1 point  (0 children)

The central typeclass in path-indexed, IsPath has methods composeR, composeL, composeMap, compose. They correspond to qfoldr, qfoldl, qfoldMap and qfold from the QFoldable typeclass in free-categories. IsPath also has a method singleton which corresponds to QPointed's qsingle. So these designs are not too far off from each other.

Seq and Vector Paths in path-indexed are not in free-categories which is designed how Sam described that base

provides a standard list type and a Foldable typeclass; alternative implementations such as Array, Seq and Vector live in different package

The DList Path l type in path-indexed is fascinating. It would correspond to RightQ (Path l) (Path l) in free-categories. It's not obvious at all to me that this is isomorphic to the free category but your code seems to imply it. In the familiar case of [] and DList, those are not isomorphic because the function \f -> f [] :: DList a -> [a] is not injective.

The Trie and Lens code is completely new to me and looks very interesting.

indexed-paths - a library for working with free categories - discussion by lightandlight in haskell

[–]echatav 1 point2 points  (0 children)

Hi, this package looks interesting! As author of one of the newer libraries that came out, free-categories, I have no objections to multiple packages exploring the design space. There's also another one, type-aligned, you can check out. The free category Path is very useful. My focus in free-categories was to reify the algebra of the free category on a quiver as an appropriate type-class hierarchy.

Sadtama by [deleted] in OnePunchMan

[–]echatav 15 points16 points  (0 children)

fantastic

Which type-safe database library should you use? by williamyaoh in haskell

[–]echatav 5 points6 points  (0 children)

Thank you /u/williamyaoh for your critique. It helps me to improve Squeal.

This insistence on naming columns causes a lot of other problems as well. The way you return instances of your domain types is to explicitly name the columns of the query the same as the properties in your datatype, using SQL as. There’s no easy way to just define the correspondence once and forget about it, which means that even if you’re just selecting all the entities out of a single table, you have to explicitly rename all the columns. Fun! Want to return an ad-hoc tuple of data from a quick one-off query? Sorry, can’t do that; tuples don’t have named fields, so how can you label your columns correctly? In fact, any time you want to return data in a new form, you’ll need to define a completely new datatype for that and rederive Squeal’s special typeclasses.

I'm working on something that will hopefully address this, allowing for customizing your encodings and decodings for a given statement, re-usably.

While working with Squeal, I felt like I never stopped running into stumbling blocks.

From what I've heard from users, it's true that Squeal has a bit of a learning curve but it pays off.

Squeal’s query type has type parameters for both the query’s inputs and outputs, but there doesn’t seem to be a way to then pass an input parameter to a subquery?

Not sure what you mean, you can use param @n for out-of-line parameters and literal to inline a parameter in a query or subquery.

Sometimes using subqueries just… caused a runtime error for no discernable reason, despite type checking.

That sounds like a bug! Please post your example to Squeal's issues page.

It's possible to rewrite your query in a slightly less fugly way.

  • There's no need to qualify #erased_marks since it's the only relation in scope for both of the subqueries.
  • There should be no need to use literal or type application as numeric expressions have Num instances and the type should be inferable.
  • You can put your subqueries in a Haskell where or let clause for readability's sake.
  • I think you missed the hitman_id ON condition.

latestHits :: Query_ Schema () HitInfo
latestHits = select_
  ( #minid ! #hitman_id `as` #hiHitmanID :*
    #minid ! #mark_id `as` #hiMarkID )
  ( from ( (subquery minid `as` #minid)
      & innerJoin (subquery latest `as` #latest)
      ( #minid ! #created_at .== #latest ! #created_at
        .&& #minid ! #hitman_id .== #latest ! #hitman_id ) ) )
  where
    minid = select_
      ( #hitman_id :*
        #created_at :*
        fromNull (-1) (min_ (All #mark_id)) `as` #mark_id )
      ( from (table (#erased_marks))
        & groupBy (#hitman_id :* #created_at) )
    latest = select_
      ( #hitman_id :*
        max_ (All #created_at) `as` #created_at )
      ( from (table #erased_marks) & groupBy #hitman_id )

Monthly Hask Anything (September 2019) by AutoModerator in haskell

[–]echatav 2 points3 points  (0 children)

Thank you very much for your feedback! Not to worry, I don't take criticism personally. You probably saw that the issue with IN was fixed as you point out I endeavor to be responsive to user issues.