[elm-discuss] Re: Encoding JSON and updating

2017-11-20 Thread David Legard
OK, thanks, I didn't fully understand your previous message.

I'll do some more tinkering with this.

-- 
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] Re: Array map with start and end

2017-11-20 Thread Francisco Ramos
Hi guys,

Thanks for your answers. Robin, that was a great talk. I actually was in
that very same room when you gave the presentation :-). Very interesting
and educative. Hope to see you again in the next Elm Europe.

Matthieu, thanks for the info. I didn't know about Okasaki's work on
immutable data structures. Have to admit I didn't google much about the
subject. Got some references and I'll go through them. I already have a
good idea about the API I'd like to implement for the ndarray. Once I get
it done (time is not something I have plenty) I'll write some benchmarks.

Ultimately, I'd like to rewrite NumElm using the elm-ndarray. Not sure how
I'm gonna do this without writing kernel code. Linear algebra operations
such as Inverse, Pseudo-inverse, Singular value decomposition, Eigenvalues
and eigenvectors, etc... I simply have no idea how I'm gonna implement
this. Need to have a look at solutions in Haskell for inspiration.

Cheers,

Fran


On Mon, Nov 20, 2017 at 4:09 PM Matthieu Pizenberg <
matthieu.pizenb...@gmail.com> wrote:

> Hi again,
>
> So out of curiosity, I just spend a couple hours looking for variations of:
> "(immutable/persistent) (tensor/multidimentional array/multidimentional
> data structure) implementation"
> and my conclusion is that I did not easily find examples of
> implementations of data structures tailored for such specific needs as
> tensor manipulation. It must not be the right way to search for this.
>
> What I found however was many references to Okasaki's work on immutable
> data structures. This question [1] with it's answer provide good starting
> points in my opinion. Okasaki's book seems to focus on how to
> design/implement fuctional data structures so it could give good insights
> for the raw data structure at the base of your ndarray type.
>
> Maybe the first thing to do would be to clearly define all the operations
> you want to have for your ndarray in some document. Then design a data
> structure considering trade-off for all the operations supported.
> Apparently, there is a paper for the numpy arrays listed on scipy website
> [2]. These are not immutable however so I don't know if it is usefull.
>
> In hope that it may help,
> Cheers,
> Matthieu
>
> [1] interesting question: https://cs.stackexchange.com/a/25953/34063
> [2] scipy citations: https://www.scipy.org/citing.html
>
> --
> 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.
>

-- 
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] Re: Array map with start and end

2017-11-20 Thread Matthieu Pizenberg
Hi again,

So out of curiosity, I just spend a couple hours looking for variations of:
"(immutable/persistent) (tensor/multidimentional array/multidimentional 
data structure) implementation"
and my conclusion is that I did not easily find examples of implementations 
of data structures tailored for such specific needs as tensor manipulation. 
It must not be the right way to search for this.

What I found however was many references to Okasaki's work on immutable 
data structures. This question [1] with it's answer provide good starting 
points in my opinion. Okasaki's book seems to focus on how to 
design/implement fuctional data structures so it could give good insights 
for the raw data structure at the base of your ndarray type.

Maybe the first thing to do would be to clearly define all the operations 
you want to have for your ndarray in some document. Then design a data 
structure considering trade-off for all the operations supported. 
Apparently, there is a paper for the numpy arrays listed on scipy website 
[2]. These are not immutable however so I don't know if it is usefull.

In hope that it may help,
Cheers,
Matthieu

[1] interesting question: https://cs.stackexchange.com/a/25953/34063
[2] scipy citations: https://www.scipy.org/citing.html

-- 
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: Encoding JSON and updating

2017-11-20 Thread Steve Schafer
Like I said in my previous message, you can't send data to that URL. That 
URL identifies the *entire* database. With PUT, PATCH, and DELETE, you have 
to use a URL that identifies a *specific *record in the database.

The error message also says that the body of the request is empty, but I 
can't tell from the message itself what the underlying problem is with that.


On Monday, November 20, 2017 at 7:53:02 AM UTC-5, David Legard wrote:
>
> OK, thanks for the suggestions.
>
> There's something going on beyond my comprehension level.
>
> I can read the data from http://localhost:3000/db, but when I try to send 
> it back, even with an Http.emptyBody, I get:
>
> BadStatus { status = { code = 404, message = "Not Found" }, headers = Dict
>> .fromList [("Cache-Control","no-cache"),("Content-Type","application/json; 
>> charset=utf-8"),("Expires","-1"),("Pragma","no-cache")], url = "
>> http://localhost:3000/db;, body = "{}" }
>>
>>
>

-- 
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: Encoding JSON and updating

2017-11-20 Thread David Legard
OK, thanks for the suggestions.

There's something going on beyond my comprehension level.

I can read the data from http://localhost:3000/db, but when I try to send 
it back, even with an Http.emptyBody, I get:

BadStatus { status = { code = 404, message = "Not Found" }, headers = 
Dict.fromList 
> [("Cache-Control","no-cache"),("Content-Type","application/json; 
> charset=utf-8"),("Expires","-1"),("Pragma","no-cache")], url = 
> "http://localhost:3000/db;, body = "{}" }
>
>

-- 
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] Re: Array map with start and end

2017-11-20 Thread Robin Heggelund Hansen
It using Array.prototype.slice under the hood, but the way Arrays in Elm is 
implemented is by using trees. I suggest you watch my talk from Elm Europe, 
where I explain how the different data structures work in detail =)

https://www.youtube.com/watch?v=mmiNobpx7eI

fredag 17. november 2017 13.34.08 UTC+1 skrev Francisco Ramos følgende:
>
> That was a good observation, Rupert. Well, it doesn't return Nothing if 
> the indexes are out of the bounds, but if start < 0 then start = 0, and end 
> >= length then end = length -1... I could actually use Array.get and 
> implement my own map like you mention.
>
> Thanks Robin for that correction. I thought Array.slice is using under the 
> hood Array.prototype.slice, which as far as I know, the C++ implementation, 
> it's O(N). If there is a new implementation with such complexity, then 
> happy days.
>
> Was just curious to know what ideas there are out there about this 
> problem. I'm aware of the fact that 2 * O(N) is still O(N), but my arrays 
> might be dealing with millions of entries. Imagine a 5000px by 5000px by 3 
> color channels. That's 75 millions. So performance is very important. 
> That's why I'm asking.
>
> Thanks guys 
>
> On Fri, Nov 17, 2017 at 1:20 PM Robin Heggelund Hansen  > wrote:
>
>> Slicing isn't O(N).
>>
>> In the current implementation in core, slicing is O(log32n) i believe. In 
>> the next version of Elm, slicing is O(log32n) when start = 0; I'm uncertain 
>> what the big-o notation is once start > 0 though.
>>
>>
>> fredag 17. november 2017 09.25.22 UTC+1 skrev Francisco Ramos følgende:
>>>
>>> Hi there,
>>>
>>> Was wondering how I can map over an array with a start and end indexes. 
>>> I know I could slice the array and then map, but performance is a concern 
>>> and slicing is O(N) where N = end - start, plus the actual mapping, another 
>>> O(N).
>>>
>>> Maybe there is another way where I just loop once over the array?
>>>
>>> Thanks a lot,
>>> Fran
>>>
>> -- 
>> 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...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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] Re: Randoms as LazyLists

2017-11-20 Thread W. Gordon Goodsman
Oh, I understand the rationale, but it limits the general usefulness of
lazy lists, as certain types of problems need memoization, and without Lazy
as it currently exists there is no way to accomplish it without JavaScript.

Just because the creators of the language don't see a need for it doesn't
mean it doesn't exist.  Even for a lazy list of random numbers, no
memoization means that new random numbers will be computed every time the
list is scanned, meaning the lazy list won't appear to be static.

On Nov 20, 2017 17:35, "'Rupert Smith' via Elm Discuss" <
elm-discuss@googlegroups.com> wrote:

> On Friday, November 17, 2017 at 1:25:02 PM UTC, GordonBGood wrote:
>>
>> The rational to depreciating these seems to be performance when applied
>> to their limited use in tests and I see that, as I tried to make changes to
>> Lazy that would improve its lack of performance when run on some JavaScript
>> engines that handle internal functions calling functions very poorly.
>>
>
> Gordon, it took me a bit of digging through various docs and updates on
> elm-dev to understand it, but... the rational for deprecating elm-core/lazy
> with memoization, is that it allowed recursive structures to be created on
> the heap, and all other ways in which that was possible have been
> eliminated. This is all described here:
>
> https://gist.github.com/evancz/07436448b7d6c947f21742dab46d1218
>
> It seems to be partly motivated by making garbage collection simpler -
> presumably with WebAssembly in mind. I honestly don't know much of a real
> advantage that is, but it seems that was the trade-off decision that has
> already been made.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Elm Discuss" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/elm-discuss/BM_ZmUk-vck/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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: Decoding a json property with different types of values

2017-11-20 Thread 'Rupert Smith' via Elm Discuss
On Friday, November 17, 2017 at 3:19:55 PM UTC, Thiago Temple wrote:
>
> I have situation where I have to a jso object similar to this
>
> { "level": 1, "displayValue": "some text", "dataValue": "a string with 
> the value" }
>
> { "level": 1, "displayValue": "some text", "dataValue": { "name": "xxx", 
> "scope": "" } }
>
> Both cases for dataValue are valid, it can either have a string or an 
> object.
>
> I have created types as such:
>
> type DataValue
>   = Val String
>   | Key KeyType
>
> type alias KeyType =
>  { name: String, source: String }
>
> type alias MyObj = 
>  { level: Int, displayValue: String, dataValue: DataValue}
>
> How can I decode dataValue for MyObj?
>
> Thanks 
>

I think the Decode.oneOf suggestion from Aaron VonderHaar is most likely to 
be useful to you.

Just to give another way, here is some decoder code for a JSON structure 
where I also added an explicit @type field to indicate which type it is to 
be decoded to. This is a little more complex, and in my case required the 
back-end to play nicely and insert the @type fields too. It does avoid the 
trial and error approach of 'oneOf' too:

{-| 
Describes the ContentModel view type. 
-} 
type ContentModel = 
TitledAsContentModel Titled 
| MdContentAsContentModel MdContent 
| PanelAsContentModel Panel 
 
{-| 
A JSON encoder for the ContentModel type. 
-} 
contentModelEncoder : ContentModel -> Encode.Value 
contentModelEncoder model = 
  case model of 
TitledAsContentModel titled -> titledEncoder titled 
MdContentAsContentModel mdContent -> mdContentEncoder mdContent 
PanelAsContentModel panel -> panelEncoder panel 
 
{-| 
A JSON decoder for the ContentModel type. 
-} 
contentModelDecoder : Decoder ContentModel 
contentModelDecoder = 
  let 
toContentModel typeName = 
  case typeName of 
"Titled" -> map TitledAsContentModel titledDecoder 
"MdContent" -> map MdContentAsContentModel mdContentDecoder 
"Panel" -> map PanelAsContentModel panelDecoder 
_ -> Decode.fail ("unknown type: " ++ typeName) 
  in 
field "@type" Decode.string 
  |> andThen toContentModel





-- 
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] Re: Randoms as LazyLists

2017-11-20 Thread 'Rupert Smith' via Elm Discuss
On Friday, November 17, 2017 at 1:25:02 PM UTC, GordonBGood wrote:
>
> The rational to depreciating these seems to be performance when applied to 
> their limited use in tests and I see that, as I tried to make changes to 
> Lazy that would improve its lack of performance when run on some JavaScript 
> engines that handle internal functions calling functions very poorly.
>

Gordon, it took me a bit of digging through various docs and updates on 
elm-dev to understand it, but... the rational for deprecating elm-core/lazy 
with memoization, is that it allowed recursive structures to be created on 
the heap, and all other ways in which that was possible have been 
eliminated. This is all described here:

https://gist.github.com/evancz/07436448b7d6c947f21742dab46d1218

It seems to be partly motivated by making garbage collection simpler - 
presumably with WebAssembly in mind. I honestly don't know much of a real 
advantage that is, but it seems that was the trade-off decision that has 
already been made.

-- 
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] Re: Array map with start and end

2017-11-20 Thread Francisco Ramos
Hi Matthieu,

Thanks for those links!!. Those lazy views look like what I'm trying to
achieve. I'm actually working on a multidimensional container of items,
elm-ndarray,
https://github.com/jscriptcoder/elm-ndarray/blob/master/src/NdArray.elm. Still
some work to do. I need to re-write *map* and *fold* since they're not
correct and implement *step*. This is based on the work of Mikola Lysenko,
https://github.com/scijs/ndarray, which in turn is based on Python ndarray,
https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.ndarray.html,
where operations such as slicing, indexing, transposing, reshaping, etc..
are all O(1). I'm missing though the possibility of using TypedArrays.

Fran

On Mon, Nov 20, 2017 at 8:01 AM Matthieu Pizenberg <
matthieu.pizenb...@gmail.com> wrote:

> Hi Francisco, just a few words about arrays and image manipulation.
>
> I've been doing some work along this way and encountered multiple issues.
> One of them was with slicing. If I'm not wrong Robin's work will be merged
> in 0.19 but meanwhile, you should be aware that there are few issues with
> the current arrays, especially large ones [1]. You can already use his
> library as a drop-in replacement though.
>
> I was also about to mention the numelm project but I think you know about
> it ^^. Regarding those kind of operations (slicing, transposing, ...) I
> think a generic image (/tensor) type would benefit a lot from having lazy
> "views" [2] and expressions of matrices as explained in the xtensor [3]
> project I mentionned in your numelm post.
>
> Cheers and good luck for this amazing project!
>
> [1] elm 0.18 array issues : https://github.com/elm-lang/core/issues/649
> [2] lazy views at 12:30 : https://youtu.be/mwIQUgigjbE?t=12m30s
> [3] https://github.com/QuantStack/xtensor
>
> --
> 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.
>

-- 
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.