[elm-discuss] Re: Json.Decode without failing on the first error?

2017-11-09 Thread Ilias Van Peer
Yeah, I did that some time ago 
- package.elm-lang.org/packages/zwilias/json-decode-exploration/latest

Demo here, the very last one in the output is a scenario not unlike yours 
:) https://ellie-app.com/3vVLfrNDnSXa1/2

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Debouncing, throttling, exponential backoff, relating effects to time - valid use of effect manager?

2017-10-29 Thread Ilias Van Peer
Your final example (exponential backoff on HTTP requests) doesn't need any 
magic.

You can use `Http.toTask` to turn it into a task and implement a generic 
"retry task at most x times with backoff" like this:

retry : Int -> Time -> Task x a -> Task x a
retry maxTries backOff task =
if maxTries == 0 then
task
else
Task.onError
(\_ ->
Process.sleep backOff
|> Task.andThen
(\_ -> retry (maxTries - 1) (backOff * 2) task)
)
task


Op zondag 29 oktober 2017 00:30:45 UTC+2 schreef Henry:
>
> Thank you Ryan for the excellent reply! You made a lot of good points, and 
> I appreciate the overview on the available libraries and their drawbacks. 
>
> I feel like the effect manager conveys the intent of the code better, you 
> get to say "I want this to happen" and then shove the state in a lock box, 
> throw it in a closet, throw the closet in a river, and pretend like the 
> hole in the side of your house was always there, and is perfectly normal. 
> The use of global string IDs is a big downside though, it feels dirty 
> writing code like that when everything else is wrapped in ribbons, laced 
> with foil, and covered in the wondrous glitter of the type system.
>
> With relating effects to time, the main examples I think of are: 
> debouncing searches, throttling clicks/events (you can only do X once every 
> 10 seconds), exponential backoff (for network requests).  I've asked a few 
> people if they know the name of that class of problems, relating events to 
> time, and I still don't know the name of them, but some friends now think 
> I'm an idiot who doesn't know what "history" is.
>
> I was trying to think of various ways it could look in the language (with 
> little regard to what is feasible...), and these are a few
>
> let
> debouncedInput = debounce 200 onInputininput [ debouncedInput 
> SearchOnServer ]
>
>
> This way the message and model are unchanged, and debouncedInput handles 
> everything auto-magically, much the same way onInput does already.  
> Ideally you could use that with Html.Events.on, or any of its ilk.  The 
> upside here is that it is very clear what is happening, because you get to 
> state it right where it happens, but it would need to be implemented in 
> VirtualDom and it would only work for HTML events.  It could be use for 
> throttling chat messages, button clicks, scroll events, etc.  The event 
> listener implementation is in VirtualDom here (
> https://github.com/elm-lang/virtual-dom/blob/dev/src/Elm/Kernel/VirtualDom.js#L521-L527
> )
>
> Another potential way (ala unbounce or mceldeen's implementations) is 
> handling the individual message, but debouncing a subsequent message.  We 
> can collect the text from the search bar, and run the search after the user 
> has quit typing.
>
> update : Msg -> Model -> ( Model, Cmd Msg )update msg model =
> case msg of
> SearchUpdate newSearch ->
> ( { model | search = newSearch }, debounce "search" 200 
> PerformSearch )
>
>
> I feel it would be even better to be able to write as
>
> ( { model | search = newSearch }, debounce 200 PerformSearch )
>
>
> For HTTP requests I would use the "second message' pattern as well, with 
> one event sending a Cmd that will resolve later and then make the 
> request.   With exponential backoff there is added state for the number of 
> tries so far, so my ideal API handles all of that for me with magic
>
> Http.getWithExponentialBackoffAndAMakeAMartini decoder 
> ("https://grass-fed-lemonade.com/search; ++ query)
>
>
> But a more realistic version is probably something like
>
> update : Msg -> Model -> ( Model, Cmd Msg )update msg model =
> case msg of
> SearchFailed err ->
> ( { model | failed = model.failed + 1 }
> , Process.sleep (model.failed * 2 * 1000)
>   |> Task.perform (\_ -> PerformSearch)
>
>
> I think any inclusion of "magic" (re: hidden state), should be weighed 
> carefully, and in this instance I think the increased clarity of the code 
> is worth it, though clarity is subjective as well.
>
> On Friday, October 13, 2017 at 5:23:45 PM UTC-4, Ryan Rempel wrote:
>>
>> On Thursday, October 5, 2017 at 9:27:27 AM UTC-5, Henry wrote:
>>>
>>> Evan has said before that there are around 10 valid uses of an effect 
>>> manager, do you think relating effects to time is one of them?
>>>
>>
>> One way of thinking about this question is to compare existing debouncers 
>> that use an effects manager vs. those which do not.
>>
>> Two debouncers which use an effects manager are:
>>
>> https://github.com/unbounce/elm-debounce
>> https://github.com/mceldeen/elm-debouncer
>>
>> Two debouncers which do not use an effects manager are:
>>
>> http://package.elm-lang.org/packages/jinjor/elm-debounce/latest
>> http://package.elm-lang.org/packages/mpizenberg/elm-debounce/latest
>>
>> Now, both approaches need to 

[elm-discuss] Re: Higher-order functions with a function using an extensible record?

2017-10-04 Thread Ilias Van Peer
mapNamed : (Named a -> b) -> Element -> b

In that line, you say that I can pass in a function that works on `Named a`, 
where `a` isn't bound to anything. So if I were to write a function `foo : 
Named { iAlsoNeedAnInt : Int } -> Int`, I could pass that to that `mapNamed`. 
However `Element` contains a very *specific* type of `Named a` - it is a `Named 
{}`.

So one thing you could do is changing the annotation to say `mapNamed : 
(Named {} -> b) -> Element -> b`. Note that this would fall apart as soon 
as the different values in `Element` actually have different types.

Note that this isn't unique to extensible records, or even records at all. 
Say you wanted to allow passing `identity` in. You could try `mapNamed : (a 
-> b) -> Element -> Element`, but that also wouldn't work.. Because I could 
pass in `(\x -> x * 7)` which has type `number -> number`, which is valid 
according to the `a -> a` shape.

I hope this clarifies things a little?

Op woensdag 4 oktober 2017 16:19:45 UTC+2 schreef Rémi Lefèvre:
>
> Hi,
>
> Does anyone know if there is a way to use higher-order functions with a 
> function using an extensible record?
>
> When I try to build this code:
>
> type alias Named a =
>{ a | name : Maybe String }
>
> getName : Named a -> Maybe String
> getName { name } =
>name
>
> type Element
>= AnElement { name : Maybe String }
>| AnotherElement { name : Maybe String }
>
> mapNamed : (Named a -> b) -> Element -> b
> mapNamed func element =
>case element of
>  AnElement e ->
> func e
>
>  AnotherElement e ->
> func e
>
> getElementName : Element -> Maybe String
> getElementName e =
>mapNamed getName e
>
>
>
> I get the following error:
>
> Detected errors in 1 module. -- TYPE MISMATCH 
> --- Types.elm The argument to function 
> `func` is causing a mismatch. 13| func e ^ Function `func` is expecting 
> the argument to be: Named a But it is: { name : Maybe String } Hint: Your 
> type annotation uses type variable `a` which means any type of value can 
> flow through. Your code is saying it CANNOT be anything though! Maybe 
> change your type annotation to be more specific? Maybe the code has a 
> problem? More at: <
> https://github.com/elm-lang/elm-compiler/blob/0.18.0/hints/type-annotations.md>
>  
>
>
>
> I struggle to understand why this does not work whereas replacing *func* 
> by *getName* satisfies the compiler:
>
> getElementName : Element -> Maybe String
> getElementName element =
>   case element of
>   AnElement e ->
>   getName e
>
>   AnotherElement e ->
>   getName e
>
>
> Any idea ?
>
> Thank you and sorry if this has been already discussed, I did not find 
> anything.
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: More pattern matching

2017-08-22 Thread Ilias Van Peer
If you're actually parsing a string, you may also want to look into one of 
the various parsing libraries like `elm-tools/parser`. If you're willing to 
give a few more details about the format of those strings, I'm sure people 
here (and on slack) would be more than willing to give you a hand in 
figuring things out.

Another alternative, in the same vein as Peter's proposals but including 
more crimes against humanity (and loosely resembling Haskell's guard 
syntax) is this one: https://ellie-app.com/46bdfm75sqja1/0

Op dinsdag 22 augustus 2017 14:46:11 UTC+2 schreef David Legard:
>
> Does Elm have anything between an *if-then-else* flow control and* case* ?
>
> My use case is, I need to parse a string in various ways to decide which 
> Analysis ADT to assign to the string.
>
> Thus
>
> sconvert : String -> Analysis
> sconvert s =
>  if s=="all" then AllDays
>  else if s=="unplayed" then Unplayed
>  else if String.startsWith "onday" s then OnDay (secondBit s)
>  else if String.contains "totz:" s then Totz (secondBit s)
>  else Unknown
>
>
> There are about 30 different branches in my app, and it's convenient to 
> keep them together.
>
> I can't use a case expression here, so I guess what I'm looking for is 
> something like F#'s match expression, where you can add conditions using 
> the when modifier. (code written as if the function existed in Elm
>
> fizzBuzz : Int -> String
> fizzBuzz x = 
> match x with 
> | i when i % 15 = 0 ->  "fizzbuzz" 
> | i when i % 3 = 0 -> "fizz" 
> | i when i % 5 = 0 ->  "buzz" 
> | i  -> toString(i)
>
> What would be an elegant way to implement the fizzBuzz function in Elm?
>   
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Discovering Elm packages

2017-08-09 Thread Ilias Van Peer
https://libraries.io/elm <- there are various rss feeds there.

Op woensdag 9 augustus 2017 15:39:50 UTC+2 schreef Vlad GURDIGA:
>
> This is nice indeed, but what I’m missing is an RSS feed, so that I don’t 
> have to remember the day when I last looked at the list, and begin scanning 
> the updates from there.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Date type not recognized

2017-06-27 Thread Ilias Van Peer
Hi Casper,

Correct, the `Date` module (and type) are not imported or exposed by 
default. You can find the default imports 
here: http://package.elm-lang.org/packages/elm-lang/core/latest

To make `Date` available in your module, you can use `import Date exposing 
(Date)`. The "exposing" part means you can reference the `Date` type 
unqualified as `Date` rather than `Date.Date`, but other functions will 
only be available when qualified (e.g. `Date.fromString`)

Good luck!

Op dinsdag 27 juni 2017 15:03:54 UTC+2 schreef Casper Bollen:
>
> For example when I use:
>
> type alias Test = { date : Date }
>
> I get an Cannot find type Date error
>
> On Tuesday, June 27, 2017 at 3:00:30 PM UTC+2, Casper Bollen wrote:
>>
>> When I want to use the Date type, it isn't recognized. Isn't this type 
>> automatically loaded with the core libs??
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Text box value displays inconsistently

2017-06-26 Thread Ilias Van Peer
Correct, this is the virtualdom reusing dom-nodes. You may want to use 
`Html.Keyed` to help the dom-diffing algorithm out by assigning unique keys 
to children that shouldn't be "mixed and matched".

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Mysterious failure to find packages during compilation

2017-06-18 Thread Ilias Van Peer
Yeah, this could be caused by "conflicting packages" - seems like you may 
have been using a different package that has a dependency on 
`elm-community/json-extra`, which uses the same module names as (and 
supersedes) `elm-community/elm-json-extra`.

Op zondag 18 juni 2017 05:08:38 UTC+2 schreef erik aker:
>
> Hi, I had a similar problem today and it turned out to be related to a 
> particular package in my elm-package.json. I noticed that after I added 
> that package, which was "elm-community/elm-json-extra": "2.3.0 <= v < 
> 3.0.0", that I would get this error about elm-lang/navigation. If I removed 
> this seemingly unrelated package from the list, the error goes away. I 
> also, like you, removed elm-stuff and tried again.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Unexpected error when parsing what seems to be reasonable code (Bug in parser maybe?)

2017-04-23 Thread Ilias Van Peer
If I'm not mistaken, this isn't so much about nested records as it is about 
referencing a qualified record in a record update expression.

This seems related to - but not exactly the same thing as 
- https://github.com/elm-lang/elm-compiler/issues/1549

So yeah, you could either create a local binding for it, use an extra 
helper function like Peter described, or expose `defaultViewConfig` in your 
imports so you can use it unqualified.

I've created a new issue for this 
- https://github.com/elm-lang/elm-compiler/issues/1587

Op zondag 23 april 2017 09:42:12 UTC+2 schreef Peter Damoc:
>
> On Sat, Apr 22, 2017 at 11:50 AM, Dwayne Crooks  > wrote:
>
>> However, if I update the let bindings as follows:
>>
>> let
>>> defaultViewConfig = Rating.defaultViewConfig
>>> ratingViewConfig =
>>> { defaultViewConfig | readOnly = model.readOnly }
>>> in
>>> ...
>>
>>
>> Then, there is no error. Am I missing something or is this a bug in the 
>> parser?
>>
>> This is related to an active topic around record update syntax. 
> In short, currently it is not allowed to directly update nested records. ({ 
> Rating.defaultViewConfig | readOnly = model.readOnly } is invalid syntax) 
> The temporary solution is the one you stumbled upon: creating an alias for 
> the nested record. 
>
> Another solution would be to use custom functions:
>
>
> updateReadOnly : { a | readOnly : Bool } -> Bool -> a
> updateReadOnly rec readOnly =
> { rec | readOnly = readOnly }
>
> and then use it like: 
>
> ratingViewConfig =
> updateReadOnly Rating.defaultViewConfig True
>
>
> -- 
> There is NO FATE, we are the creators.
> blog: http://damoc.ro/
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Publishing Elm package that depends on web components

2017-03-16 Thread Ilias Van Peer
I actually found some prior art 
- http://package.elm-lang.org/packages/kkpoon/elm-echarts/latest


Op woensdag 15 maart 2017 18:11:12 UTC+1 schreef Jonas Schürmann:
>
> Hey folks,
>
> is it okay to publish a pure Elm package (no native code, no ports) that 
> depends on a custom element (web component) being defined by some other 
> Javascript library?
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Cmd Msg returned by init

2017-03-11 Thread Ilias Van Peer
Let's take a step back, here.

Conceptually, the `init` function is meant to say how to jumpstart your 
application. So what it should do, is provide the initial state of your 
model, and - optionally - telling the runtime to start executing some 
asynchronous task right away (a good example would be fetching some remote 
resource), as a Cmd.

When the runtime receives such a Cmd, it will do what your commanded it to 
do, and then call your `update` function with the current state of the 
model and the Msg that resulted from your Cmd.

Using `Task.perform` with a "no op" task to "trick" the runtime into 
calling your update feels wrong, as you say yourself. I'd argue that it's 
definitely abusing the the runtime, too.

So, let's have a look at what you are trying to accomplish: you want to 
execute a function on your model, before declaring it "final". You could do 
that by calling `update` with the appropriate Msg from your init function, 
*or* you could split off that branch into a proper function that transforms 
your model.

What you'd end up with, then, is something like this:

```
init : (Model, Cmd msg)
init =
 ( initialModel |> transformIt, Cmd.none)
```

Your update function would call that exact same function - which means you 
could think of the update function like a sort of "translation" from 
messages to function calls that transform your model, rather than the one 
central place to bundle all your logic.

Hope this helps :)

Kr,

Ilias

Op woensdag 8 maart 2017 22:50:00 UTC+1 schreef Duane Johnson:
>
> Preface: while I've been using Elm for a while, I've only just begun using 
> messages and commands, so it's ok to treat me like a newbie here. This is a 
> capture of my experience of Elm while trying to figure out how to send an 
> initial message.
>
>
> I find the `Cmd` type a little confusing, especially in the init function. 
> Conceptually, I want to "kick off" an initial fetch of data from client to 
> server, and it would make intuitive sense if I were permitted to do this:
>
> ```
> init : (Model, Msg)
> init =
> { initialModel, FetchStatus 0 }
> ```
>
> But instead, the type of `init` is required to be this:
>
> ```
> init : (Model, Cmd Msg)
> init =
> { initialModel, ... }
> ```
>
> When I get to this point, I need to look up the documentation on Cmd. 
> Having read the guide several months ago, I have a vague impression that I 
> may need to "perform" something to get my message into a Cmd type. I look 
> at the `Platform.Cmd` documentation, and I see there's a `Cmd` type which 
> looks like a constructor. So I try this:
>
> ```
> init : (Model, Cmd Msg)
> init =
> { initialModel, Cmd (FetchStatus 0) }
> ```
>
> But I get an error: "Cannot find variable `Cmd`". Having some experience 
> with Elm, I believe this may mean although Cmd is a type, its constructor 
> is not exposed.
>
> At this point, the `map` function looks a little promising, because it 
> takes some things that are not Cmd and produces `Cmd msg`, i.e. precisely 
> the type I'm looking for. However, it's not clear to me what the first 
> parameter to map is (a function that takes `a` and produces `msg`?) There's 
> no documentation on this `map` function.
>
> Then I peruse the docs some more ("maybe this is so common a thing that it 
> belongs in Basics? or maybe I missed something in Platform, since Cmd is a 
> submodule of Platform?") and arrive at the Task documentation, where I see 
> the "perform" signature:
>
> perform 
>  : 
> (a -> msg) -> Task 
>  Never 
>  a 
> -> Cmd 
>  
> msg
>
> This looks promising as well, because it takes some things and produces a 
> `Cmd msg`. But the example in the documentation shows how to use `perform` 
> with `Time.now` which further confuses things because I just want to pass a 
> Time value to my FetchStatus, like it was meant to receive (not necessarily 
> a "now" value). If I try this:
>
> ```
> init : ( Model, Cmd Msg )
> init =
> ( initialModel, Task.perform FetchStatus 0 )
> ```
>
> I get
>
> ```
> Function `perform` is expecting the 2nd argument to be:
> Task.Task Never Time
> ```
>
> So finally I realize that I need to pass a "succeed" task to my `perform` 
> call so I can create a `Cmd msg` of the type I need:
>
> ```
> init : ( Model, Cmd Msg )
> init =
> ( initialModel, Task.perform FetchStatus (Task.succeed 0) )
> ```
>
> Subjectively, this all feels more convoluted than it needs to be. At a 
> basic level, I want to communicate an initial model and an initial "kick 
> off" message. It's confusing that Task types are involved in constructing 
> Cmd types. This makes finding the right documentation difficult. In 
> addition, it isn't clear why a Cmd is needed