open-sorcerers / madlib

Madlib: a compile-to-JS language written in Haskell, designed to make writing code a delight
https://github.com/madlib-lang/madlib
BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

Low-Friction From-JS Porpoises #35

Open brekk opened 3 years ago

brekk commented 3 years ago

We have some rough edges when coming from a JS context still, this issue can ideally enumerate them as we work through them.

aboeglin commented 3 years ago

Implementation thoughts on it:

  1. Very simple, it's mostly a syntax sugar and is about a line to add in the grammar.
  2. The grammar and typecheck part should be simple, but we need to give thoughts about how it should be used and if we want to add specific operators that deal with regexes ( =~ or so ).
  3. The main issue we have with this is that we can't type check it. That's mainly where Map comes in. That might feel limited coming from JS, but I think the trade-off is worth it. Also we could technically add a [] operator to Map to make it look like this ? We can do all the rest though, we can spread, we can deconstruct ( well pattern match in a way more powerful way even ). The issue is, say you have a function that does: setForKey :: String -> a -> { whatIsThatKey :: a }.
  4. I have tested the following just now and it seems to work fine:
    import IO from "IO"
    fn = (_) => ({})
    fn(2) |> IO.log

    Did you mean something else ?

  5. Also very simple, but mainly I'd wait until we know more where the formatting is going. In a more Haskell-like formatting I think it's less of an issue:
    [ x1
    , x2
    , x3
    ]
brekk commented 3 years ago

For 5, it's valid in JS to do [a, b, c,].

aboeglin commented 3 years ago

Oh yes it is for a while now. But what I was saying is that we might want to have one valid syntax that passes the linter and that is formatted by our code formatter. And we did not yet define how we want things to be formatted. I think the argument for trailing commas is mainly to make diffs nicer but also adding a line being consistent with the previous one. That being said I think we should indeed probably aim for something close to what prettier would do in terms of formatting.