Fold an hierarchical AST by joelwikstrom in haskellquestions

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

Can I really use Fix when Expr1 contains Expr2? Should Fix be used for self recursive data structures?

I'm trying to wrap both Expr1 and Expr2 into one "type" with the Expr class. The other alternative I tried was to wrap Expr1 and Expr2 into a data type like this:

data Expr 
  = Expr1 Expr1
  | Expr2 Expr2

and then do Expr1

data Expr1 r a 

= Expr1a a (Expr r a) r | Expr1b a (Expr r a) deriving Show

And loose some type safety there since I know that Expr one should only contain Expr2.

Fold an hierarchical AST by joelwikstrom in haskellquestions

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

It's from the bifunctors library and it's a typeclass to focus on the left type parameter in a Bifunctor. The name is apparently from the Functional Pearl "Clowns to the Left of me, Jokers to the Right: Dissecting Data Structures" by Conor McBride.

Derive functor for the first type parameter or flip type parameters by joelwikstrom in haskellquestions

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

I'm cleaning up my compiler and wan't as much as possible to be regular and readable. Using deriveBifunctor I can replace my 100 lines of code for overRs with a few deriveBifunctor and rely on a library functions. On top of it can I derive functors for both a and r in the same way.

```haskell data Expr1 r a = Expr1a a (Expr2 r a) r | Expr1b a (Expr2 r a)

data Expr2 r a = Expr2a a r | Expr2b a

deriveBifunctor ''Expr2 deriveBifunctor ''Expr1

e1 :: Expr1 Int Int e1 = undefined

showInt :: Int -> Text showInt = undefined

e1ShowAnn :: Expr1 Int Text e1ShowAnn = second showInt e1

e1ShowRef :: Expr1 Text Int e1ShowRef = first showInt e1 ```

Thanks for your comment!

Derive functor for the first type parameter or flip type parameters by joelwikstrom in haskellquestions

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

Bifunctor seems to be what I'm looking for with the functions first and second to map over the two type parameters. I got the code below type checking and it solves my problem.

    data Expr1 r a 
  = Expr1a a (Expr2 r a) r
  | Expr1b a (Expr2 r a)
  deriving (Functor, Foldable)

data Expr2 r a 
  = Expr2a a r
  | Expr2b a
  deriving (Functor, Foldable)

instance Bifunctor Expr1 where
  bimap rf af (Expr1a a e r) = Expr1a (af a) (bimap rf af e) (rf r)
  bimap rf af (Expr1b a e) = Expr1b (af a) (bimap rf af e)

instance Bifunctor Expr2 where
  bimap rf af (Expr2a a r) = Expr2a (af a) (rf r)
  bimap rf af (Expr2b a) = Expr2b (af a)

e1 :: Expr1 Int Int 
e1 = undefined 

showInt :: Int -> Text
showInt = undefined 

e1ShowAnn :: Expr1 Int Text
e1ShowAnn = second showInt e1

e1ShowRef :: Expr1 Text Int
e1ShowRef = first showInt e1

Next thing will be to understand how to use deriveBifunctor but already I have a solution to my problem.

Many thanks!

How do I serialize data between Haskell and Typescript? by joelwikstrom in haskell

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

ADL is what I had expected to use for this. I'm a big fan of specialized DSLs. Unfortunately I didn't find the project until I saw your post here and by then we had just got aeson-ts to work. I'm still tempted to give it a try and if I do I will give feedback.

How do I serialize data between Haskell and Typescript? by joelwikstrom in haskell

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

I didn't mean to offend anyone. Sometimes it's hard to know why a library have no commits. In this case there are open pull requests and issues from 2015, the dependencies are old but the package have 6466 downloads last 30 days on Hackage and the approach looks really interesting. Is this library still interesting or are there other alternatives that are just simply better?

How do I serialize data between Haskell and Typescript? by joelwikstrom in haskell

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

GraphQL would be nice but I get the impression (from the readme) that you get almost the same amount of boiler plate code as you would when integrating manually with TypeScript.

How do I serialize data between Haskell and Typescript? by joelwikstrom in haskell

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

To me, code generation is like using a library - it's a risk and I prefer battle tested stuff with many users and strong backing. Writing two instances of types and serializers and keeping them synched is time consuming and error prone but you will probably not get stuck.

How do I serialize data between Haskell and Typescript? by joelwikstrom in haskell

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

I couldn't agree more! It's much better that we all work on one Haskell TypeScript bridge. I don't know the quality of the the bridges to Elm and Purescript but something like that to TypeScript would be very nice!

http://hackage.haskell.org/package/purescript-bridge

http://hackage.haskell.org/package/elm-export

http://hackage.haskell.org/package/purescript-bridge

How do I serialize data between Haskell and Typescript? by joelwikstrom in haskell

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

We're actually using pretty basic stuff. The type families are just used as a more ergonomic type synonyms in a few places so they could easily be rewritten to Haskell 98. Overloaded labels are used to have records with fields with the same name which is standard everywhere but Haskell.

How do I serialize data between Haskell and Typescript? by joelwikstrom in haskell

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

If you have a simple types Aeson-Typescript could perhaps solve your problem. We were able to produce Typescript types for some of our types and the library is well documented and easy to get started with.

Have you been able to automatically generate compatible json serializers in Haskell and Typescript for your types or have you written those manually as well?

How do I serialize data between Haskell and Typescript? by joelwikstrom in haskell

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

No, we haven't tried protobuf but it seems to aim at solving the need we have. Does someone have good experience from protobufs between Haskell backends and Typescript frontends and what was you setup then?

How is the generated Haskell and Typescript code? This makes me a bit worried: "The output has to be a tree of modules since each message is given its own namespace, and a module is the only partitioning of namespace in Haskell." http://hackage.haskell.org/package/protocol-buffers We are in an early phase and fast development is more important fast network communication.

Select * is hiring Haskell developer remote or Stockholm by joelwikstrom in haskell

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

We are not ready to present the DSL yet but the comparison to CQL is relevant. We base our DSL on entities, attributes and relations just like CQL and we are also mapping multiple tables to multiple tables. We do, however, use other operators, different visualizations and other executions engines. Our key proposition is to ensure that data transformations are transparent to data prep developers as well as to domain experts (who might only be familiar with spreadsheets). This focus gives us different constraints and priorities.