workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
elmlang | general | the `whatever` can't be a `string` (that you ignore), i.e. it can have `/` characters in it? | 2019-03-10T10:05:14.731100 | Virgie |
elmlang | general | yep, it can contain the rest of uri. I found a simple way - just add cleaning of uri before putting it to this function. Thank you! | 2019-03-10T10:08:37.732500 | Carroll |
elmlang | general | This talk about labels in property based tests is very helpful and describes how to work with property based tests if you're used to write unit tests. <https://youtu.be/NcJOiQlzlXQ>
Now I'm thinking if there is a way to have fuzz tests in `elm-test` with labels to follow the advice John Hughes was giving at lambda days. Nice talk :slightly_smiling_face: | 2019-03-10T13:03:41.732900 | Millie |
elmlang | general | Could someone walk me through implementing a “mini-markdown” parser with elm/parser? I could send a bit of $$ your way if that would help. OR I can put the work (with attribution) towards an open source wysiwyg editor component I have an idea for. (edited) | 2019-03-10T15:27:13.736000 | Leoma |
elmlang | general | Hey if you figure out how to do this, I'd love to know as well! | 2019-03-10T15:58:08.736100 | Ann |
elmlang | general | Ya, I’m working on it until I figure it out, or get help. | 2019-03-10T15:58:56.736600 | Leoma |
elmlang | general | I’m not qualified enough to ask for $$ but happy to bang my head on problems you want to post here :wink: | 2019-03-10T16:24:02.741900 | Dede |
elmlang | general | I also need something similar, at least the bold/italic/underline part, and will work on it soon, but maybe not right now.
I intent to get inspiration from <https://github.com/jgm/cheapskate>, as advised here:
<https://github.com/elm/projects/blob/master/README.md#markdown-parser>
and would advise you to do the same. I gave it a look and I'm pretty sure you can implement it without backtracking. | 2019-03-10T16:27:12.742200 | Velia |
elmlang | general | Thinking about the backtracking question: informally, imagine
```
succeed tidleOrItalics
|. token "~~"
|= getChompedString chompWhile notNewlineOrTwoTildes
|= getChompedString <| chompNewlineOrTwoTildes
```
Then `tildeOrItalics` can look at the third argument to decide what to do with the string and the leading tildes.
Does that make sense? | 2019-03-10T16:32:26.742600 | Dede |
elmlang | general | Nesting obviously gets more complex. | 2019-03-10T16:32:39.742800 | Dede |
elmlang | general | So, this is my AST:
```
type Styled
= Plain String
| URL String
| Bold Styled
| Italic Styled
| Underline Styled
| StyledList (List Styled)
type Content
= StyledContent Styled
| NewLine
``` | 2019-03-10T16:34:11.743000 | Leoma |
elmlang | general | Importantly I can parse plain text, URL, and lists of these things. Then a style item can be bold,italic,underline and part of a list that has other styles applied | 2019-03-10T16:35:08.743200 | Leoma |
elmlang | general | Ultimately I’d want a `Parser (List Content)` | 2019-03-10T16:35:25.743400 | Leoma |
elmlang | general | The plan is that `/` followed by non-whitespace indicated start-italic, and non-whitespace followed by `/` closes italics. `_` for underline, and `*` for bold. | 2019-03-10T16:37:03.744400 | Leoma |
elmlang | general | `/italic/ _underline_ *bold* *_/confusingBroken?` | 2019-03-10T16:38:03.745200 | Dede |
elmlang | general | stuff like `/this is italic and (6/2=3)/` should be all italic. | 2019-03-10T16:38:05.745500 | Leoma |
elmlang | general | `/*boldOrItalicOrWhat/* ?` | 2019-03-10T16:38:19.746000 | Dede |
elmlang | general | I believe you need something like:
```
type Markdown
= Markdown (List Text)
type Text
= Literal String
| Bold Markdown
| Italic Markdown
| Underlined Markdown
``` | 2019-03-10T16:38:26.746200 | Velia |
elmlang | general | `_*/all3/*_` is fine | 2019-03-10T16:38:27.746400 | Leoma |
elmlang | general | This is close to the haskell version:
<https://github.com/jgm/cheapskate/blob/49b2d9dcc4a32c7304ec545c2d1ef45ecf5ee3de/Cheapskate/Types.hs#L47>
```
-- | Inline elements.
data Inline = Str Text
| Space
| SoftBreak
| LineBreak
| Emph Inlines
| Strong Inlines
| Code Text
| Link Inlines Text {- URL -} Text {- title -}
| Image Inlines Text {- URL -} Text {- title -}
| Entity Text
| RawHtml Text
deriving (Show, Data, Typeable)
type Inlines = Seq Inline
``` | 2019-03-10T16:39:44.747600 | Velia |
elmlang | general | I have an interesting conundrum, essentially I think I'm in need of a Maybe-unwrapping `if-let`, if that makes sense:
```
try* : X -> Maybe Y -- let's say those are expensive
use : Y -> Z
fallback : Z
fn x : X -> Z
fn x =
if-let (try1 x) as y then
use y
else if-let (try2 x) as y then
use y
else if-let (try3 x) as y then
use y
else if-let (try4 x) as y then
use y
else
fallback
```
now that's a made-up syntax but I don't know how to get to a similar effect with what Elm offers.
```
fn x =
try1 x
|> Maybe.Extra.orElse (try2 x)
|> Maybe.Extra.orElse (try3 x)
|> Maybe.Extra.orElse (try4 x)
|> Maybe.map use
|> Maybe.withDefault fallback
```
has the disadvantage that it runs all four `try` functions eagerly
```
fn x =
case try1 x of
Just y ->
use x
Nothing ->
case try2 x of
...
```
has a shape fireballing out of control... | 2019-03-10T16:41:12.748800 | Florencia |
elmlang | general | Can you make an orElse that takes a thunk? | 2019-03-10T16:42:07.750100 | Leoma |
elmlang | general | `orElse (\() -> try2 x)` | 2019-03-10T16:42:34.751000 | Leoma |
elmlang | general | Now that I think of it, probably the best thing to do here is
```
getY : X -> Maybe Y
getY x =
-- probably something like
if ... then
...
else if ... then
...
else if ... then
...
else if ... then
...
else
Nothing
fn x =
getY x
|> Maybe.map use
|> Maybe.withDefault fallback
``` | 2019-03-10T16:43:12.751700 | Florencia |
elmlang | general | I probably can | 2019-03-10T16:43:19.752000 | Florencia |
elmlang | general | (`orElseLazy` is a thing, too, btw) | 2019-03-10T16:45:15.752400 | Huong |
elmlang | general | Anyway I think the tricky part is a gracefully failing parser. Like, `/not italic *this is bold*` should at least show the bold stuff as bold.
So, seeing `/not ...` isn’t enough to commit to italics. | 2019-03-10T16:47:51.752600 | Leoma |
elmlang | general | You should only commit when closing a style. | 2019-03-10T16:48:58.752800 | Velia |
elmlang | general | Right. So, I need lot’s of `Parser.backtrackable` | 2019-03-10T16:50:46.753000 | Leoma |
elmlang | general | It’ll be fine as the styles are per line. So complexity shouldn’t get out of hand. | 2019-03-10T16:51:06.753200 | Leoma |
elmlang | general | I still disagree. Working on a grammar. | 2019-03-10T16:51:08.753400 | Dede |
elmlang | general | I believe backtrackable is not needed, an `andThen` when closing a style to finalize it should be enough. It's still not trivial to organize the lists of texts with potential styles though. But I'm pretty sure the haskell version does something very similar (just a guess). | 2019-03-10T16:52:33.753600 | Velia |
elmlang | general | This is a sort of ad hoc LALR style grammar:
```
-- A line is an element and a newline
line = element newline
| element whitespace newline
-- element has no whitespace at its edges
element = italic
| bold
| underlined
| nonWhitespace
| element whitespace element
italic = "/" element "/"
bold = ...
``` | 2019-03-10T16:54:40.754100 | Dede |
elmlang | general | Implementing this manually, you maintain a lot of undecided state on the stack. | 2019-03-10T16:55:06.754400 | Dede |
elmlang | general | I see at least one bug in my grammar, working… | 2019-03-10T16:56:06.754600 | Dede |
elmlang | general | You can only have 3 undecided states, as nested bold for example is not possible (the same style cannot be nested). | 2019-03-10T16:56:18.754800 | Velia |
elmlang | general | Ahhh ok. I see. We don’t need backtrackable but it might make code simpler. | 2019-03-10T16:58:04.755900 | Leoma |
elmlang | general | Back online in a few hours | 2019-03-10T16:58:54.756400 | Leoma |
elmlang | general | Yeah, I gotta run as well. | 2019-03-10T17:01:25.756600 | Dede |
elmlang | general | so far liking what i see in elm. it's almost too simple, | 2019-03-10T17:03:49.757600 | Lupita |
elmlang | general | Haskell uses alternative's `<|>` for that | 2019-03-10T17:49:09.758300 | Kris |
elmlang | general | `a <|> b <|> c <|> d` returns the first maybe that's a just | 2019-03-10T17:49:21.758700 | Kris |
elmlang | general | `asum [a, b, c, d]` in short :smile: | 2019-03-10T18:53:01.759300 | Niesha |
elmlang | general | In an effort to understand how the Elm compiler works, I forked it to add support for compiling Kernel modules for local apps - <https://github.com/Checksum/elm-compiler>. I'm sure it's been done before, but I was pleasantly surprised at how Haskell felt familiar thanks to Elm! This is the first line of Haskell code I've ever written in my life :slightly_smiling_face:
*This is just an experiment by an Elm beginner. Please don't actually use this!* | 2019-03-10T19:20:59.761200 | Kyung |
elmlang | general | i'm trying a base project for Browser.elements. i'm not how to now initiate an http request <https://ellie-app.com/4WNFh2BnTKHa1> | 2019-03-10T19:31:34.762200 | Lupita |
elmlang | general | getting a compile error | 2019-03-10T19:31:50.762500 | Lupita |
elmlang | general | `{ ... } => ( ... )` in init | 2019-03-10T19:34:21.762900 | Kris |
elmlang | general | Is anyone else getting just the loading screen on Ellie? I can't seem to access it the last couple of days (tried the usual clear cache, private window, etc) | 2019-03-10T19:36:03.763800 | Kyung |
elmlang | general | ok, changed to () | 2019-03-10T19:37:25.764000 | Lupita |
elmlang | general | ok works, is this a good base for all projects now? <https://ellie-app.com/4WP4XkvFfsqa1> | 2019-03-10T19:46:47.764500 | Lupita |
elmlang | general | Evan did a presentation talking about improving compiler errors. He said the creator of scala was there taking notes. I don’t recall where I heard him mention it. If I had to guess I’d say it was:
<https://player.fm/series/elixir-fountain/elixir-fountain-evan-czaplicki-2016-07-11>
But I could be totally wrong about the source. | 2019-03-10T20:09:39.764600 | Delois |
elmlang | general | Can someone demystify the `Parser` type for me? Both the Url parser docs (<https://package.elm-lang.org/packages/elm/url/latest/Url-Parser>) and the guide glance over this `Parser a b` type, but it's so prevalent in any code associated to Url parsing. More specifically, what does the `a` represent and what does the `b` represent in `Parser a b`?
As a follow up, if i have a parser of type `Parser (Route -> a) a` (like the one in the Url parsing guide), and i call `parse`on this parser (which has a signature of `Parser (a -> a) a -> Url -> Maybe a)`, don't I get a `Maybe Route`? This further seems to confuse me | 2019-03-10T20:17:16.767700 | Al |
elmlang | general | <@Kyung> I haven't been able to access it for the last few days either | 2019-03-10T21:44:31.769300 | Tom |
elmlang | general | finished my example <https://ellie-app.com/4WRcGdhshcGa1> | 2019-03-10T22:28:09.769700 | Lupita |
elmlang | general | nice. I’d recommend looking into RemoteData for your text | 2019-03-10T22:40:36.769800 | Hoyt |
elmlang | general | oh man, just another thing to learn. | 2019-03-10T22:51:22.770000 | Lupita |
elmlang | general | is this something that you use? | 2019-03-10T22:52:58.770200 | Lupita |
elmlang | general | Pretty much always when I’m loading data from an external endpoint | 2019-03-10T23:11:07.770400 | Hoyt |
elmlang | general | Here’s a really great video to watch about it <https://www.youtube.com/watch?v=NLcRzOyrH08> Definitely helps getting into the elm mindset | 2019-03-10T23:12:28.770600 | Hoyt |
elmlang | general | thanks!! | 2019-03-10T23:15:50.770800 | Lupita |
elmlang | general | OK, here’s a more detailed shot at a permissive grammar. This is not in a formal grammar language, it’s just an illustrative ad hoc approach.
```
whitespaceChar = CHARS IN ['\t', ' ']
whitespace =
whitespaceChar
| whitespace whitespaceChar
plainChar = CHARS NOT IN ['\t', ' ', '/', '*']
plain =
plainChar
| plain plainChar
| plain '*' plainChar -- handle * in middle of text
| plain '/' plainChar -- handle / in middle of text
atom =
plain
| bold
| italic
| '*' -- handle free-standing *
| '/' -- handle free-standing /
| atom whitespace atom
| atom '*' -- handle trailing '*' with no opener -- see conflict note (1) below
| atom '/' -- handle trailing '/' with no opener -- see conflict note (2) below
openItalic = '/' body
openBold = '*' body
body =
atom
| openItalic
| openBold
| body whitespace atom
| body whitespace openItalic
| body whitespace openBold
bold = openBold '*' -- see conflict note (1) below
italic = openItalic '/' -- see conflict note (2) below
lineContent =
atom
| openItalic
| openBold
line =
lineContent newline
| lineContent whitespace newline
| whitespace lineContent newline
| whitespace lineContent whitespace newline
-- Conflict notes
--
-- 1) There are conflicts in the two rules flagged by this note. For the input "*hello*",
-- one potential match is
--
-- (bold = openBold '*') where (openBold = '*' body) where (body = atom) where (atom = plain("hello"))
--
-- another potential match is
--
-- (openBold = '*' body) where (body = atom) where (atom = atom '*') where (atom = plain("hello")
--
-- Since we prefer the first rule, our implementation should give it precedence when both are applicable.
--
-- 2) Same exact comment as above, except for italics
``` | 2019-03-11T00:40:52.771100 | Dede |
elmlang | general | A traditional parser generator like bison would take something like this and turn it into a state machine that could parse the input in a non-backtracking manner.
Since this grammar is mostly simple, you can probably implement it in a fairly straightforward way translating to Elm parser. The area I highlighted with comments is where there’s some rule ambiguity that you’ll have to specifically address. | 2019-03-11T00:44:52.771300 | Dede |
elmlang | general | Bison and its ilk generally look at the next “token” in the stream to decide which rule(s) could be applicable. Even hand-coded, that approach might be profitable here. | 2019-03-11T00:45:34.771500 | Dede |
elmlang | general | There’s probably more ambiguities that I haven’t identified. E.g. I think you’ll need to address what to do with “/where do the /italics start/?” | 2019-03-11T00:58:15.771700 | Dede |
elmlang | general | Bedtime here, I should be around on and off tomorrow. | 2019-03-11T00:58:33.771900 | Dede |
elmlang | general | I hope this is helpful and not (just) bloviating. | 2019-03-11T00:58:47.772100 | Dede |
elmlang | general | Good question! | 2019-03-11T02:02:04.772300 | Carlota |
elmlang | general | Let's dig in. | 2019-03-11T02:02:07.772500 | Carlota |
elmlang | general | "Turn URLs like /blog/42/cat-herding-techniques into nice Elm data." | 2019-03-11T02:03:52.772700 | Carlota |
elmlang | general | That's what the `type Parser a b` type says under it. | 2019-03-11T02:04:09.772900 | Carlota |
elmlang | general | You know you've been converted when you opine the joys of functional programming to your mates in programming classes | 2019-03-11T02:04:56.774200 | Isaias |
elmlang | general | So, you can pretty much ignore the type, I reckon. | 2019-03-11T02:06:36.774300 | Carlota |
elmlang | general | and look at the examples. | 2019-03-11T02:06:41.774500 | Carlota |
elmlang | general | ... if you look at the type of `parse`, which runs a parser, it becomes a bit more apparent why it's not that important: `parse : Parser (a -> a) a -> Url -> Maybe a` | 2019-03-11T02:08:54.774700 | Carlota |
elmlang | general | So it takes some `Parser (a -> a) a` and a `Url` and gives you back a `Maybe a`. Super confusing. | 2019-03-11T02:09:38.775000 | Carlota |
elmlang | general | If you look at the example for `parse` it's more helpful... | 2019-03-11T02:12:06.775200 | Carlota |
elmlang | general | ... and let's take the `search` example in `</>`:
```
search : Parser (String -> a) a
search =
s "search" </> string
``` | 2019-03-11T02:12:26.775400 | Carlota |
elmlang | general | so the `Parser a b` type there is where `a` is `String -> a` (different `a` tho, let's not get confused) and `b` is `a`. If we rename `Parser a b` to `Parser x y` temporarily it's easier: `Parser x y` means `x` is `String -> a` and `y` is `a`. | 2019-03-11T02:14:11.775600 | Carlota |
elmlang | general | If we look at that side by side with this:
```
type Route = Home | Blog Int | NotFound
route : Parser (Route -> a) a
route =
oneOf
[ map Home top
, map Blog (s "blog" </> int)
]
toRoute : String -> Route
toRoute string =
case Url.fromString string of
Nothing ->
NotFound
Just url ->
Maybe.withDefault NotFound (parse route url)
``` | 2019-03-11T02:14:40.775800 | Carlota |
elmlang | general | ... then things start becoming clearer, coz they have a `route : (Route -> a) a`... and they're using `map` to map the `Route` type's constructors over the ordinary parsers: for `Home` they're mapping over `top`, which parses nothing out, so that works coz `Home` takes no arguments. For `Blog`, which takes a single `int`, they've got `s "blog" </> int"` which is a parser of `Parser (String -> a) a` (as we saw in the example above for `search : Parser (String -> a) a` which is `s "search" </> string`.) | 2019-03-11T02:16:58.776000 | Carlota |
elmlang | general | below, in `toRoute`, we can see they're using `parse route url` to match the function `route` as type `Parser (a -> a) a`. `route` has type `Parser (Route -> a) a` so that totally matches. | 2019-03-11T02:23:29.776400 | Carlota |
elmlang | general | The thing about this Parser type is you should *actively ignore* the `a b` stuff. It's opaque, which means they don't want you to "look inside". Unfortunately, the pieces it exposes are necessary to make the type system able to write our actual code, so we have to have these ugly exposed type parameters. | 2019-03-11T02:24:26.776600 | Carlota |
elmlang | general | You can think of the `a b` part of `Parser a b` as the internal parser state, though, if you like — ie what it's holding on to to do its job — which is to track all the segments of the route that have matched or not, and the functions you want to use to do the parsing with. | 2019-03-11T02:25:24.776800 | Carlota |
elmlang | general | > As a follow up, if i have a parser of type `Parser (Route -> a) a` (like the one in the Url parsing guide), and i call `parse`on this parser (which has a signature of `Parser (a -> a) a -> Url -> Maybe a)`, don't I get a `Maybe Route`? This further seems to confuse me
Yeah, that's right. | 2019-03-11T02:26:24.777000 | Carlota |
elmlang | general | Basically, you can't see into what it's doing by trying to look at the types, which is why this is confusing from the outside. | 2019-03-11T02:29:05.777200 | Carlota |
elmlang | general | It helps to know that a `Parser a b` in the `Url` sense combined with the `parse` function is a function from `String` to a `Maybe a`, where you decide what `a` is. It does this by keeping lists of internal state matchers. When you use the `</>` function, you're combining these state matchers with a kind of `andThen` on the prior success of the previous parsers and their result succeeding. | 2019-03-11T02:40:05.777400 | Carlota |
elmlang | general | But, IMO, it's best to just build it up by using it with examples, bit by bit until you have an intuition about how to use them. | 2019-03-11T02:40:31.777600 | Carlota |
elmlang | general | If you want to dig into the internals, they're there... but they probably won't be *terribly* helpful to understanding how to use it. The examples are tho :slightly_smiling_face: | 2019-03-11T02:41:23.777800 | Carlota |
elmlang | general | Hey! Elm module names must match the file path, right? It's more or less compiler's requirement. Also they need to be under one of `source-directories` specified in `elm.json`. Is it mentioned anywhere in the documentation? I'm trying to provide a link but can't find it. | 2019-03-11T05:16:32.780300 | Dorsey |
elmlang | general | I cannot open <https://ellie-app.com/> anymore, in Chrome and Firefox it stays stuck in the Ellie logo. Anyone seeing this? | 2019-03-11T05:20:22.781200 | Carrol |
elmlang | general | <@Dorsey> It is mentioned here <https://guide.elm-lang.org/webapps/modules.html> under "Using modules", there is also a link to the structure of `elm.json` for applications which describes what "source-directories" is | 2019-03-11T05:22:20.782400 | Lynne |
elmlang | general | Oh, thanks! | 2019-03-11T05:22:43.782600 | Dorsey |
elmlang | general | Works for me. Might be some temporary issue depending on where you are | 2019-03-11T05:22:46.782800 | Lynne |
elmlang | general | :heart: | 2019-03-11T05:22:50.783000 | Dorsey |
elmlang | general | ok, thanks | 2019-03-11T05:22:58.783100 | Carrol |
elmlang | general | How to make List of Headers from List of Strings? | 2019-03-11T05:41:30.783400 | Monty |
elmlang | general | Is it some undocumented feature that when I use a `Browser.application` that it replaces all the nodes in the `body` element for my application? | 2019-03-11T05:43:43.784400 | Kitty |
elmlang | general | `headers = [Http.header "Access-Control-Allow-Origin" "<http://localhost:8080>"]` | 2019-03-11T05:44:09.784600 | Lynne |
elmlang | general | Yes, unfortunately | 2019-03-11T05:44:48.785200 | Lynne |
elmlang | general | that really caught me off guard, I cant find it in the documentation anywhere | 2019-03-11T05:49:27.785600 | Kitty |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.