Re: [elm-discuss] Re: Stance on native APIs for 0.18?

2016-12-08 Thread Wil C


So now, either I write a ports for commonmark.js, or I write it as a native 
>> module. I asked about it here 
>>  with 
>> no answers. 
>>
>
> I think if you write it as ports or native, you'll still need to map the 
> AST between javascript and Elm. As a native module that could be done with 
> a Decoder or by constructing the Elm AST in native code with Javascript. 
> Perhaps Decoders are not so bad?
>

In the case of using commonmark.js, I didn't use a decoder. Taking a page 
out of the elm-markdown playbook, I call directly into VirtualDom's js calls 
. 
My guess is that Evan did it as a hack. And since it's not a published API, 
I don't expect it to stick around. Reaching into a private API is usually 
bad news. I chose not to write decoders in this case, because I'm using 
commonmark.js already, so it's not like I could share the code as a lib. 
And it's admittedly a shortcut.

In the case of parsing SQL, I did end up using a decoder. I sent the sql 
string into a port, had it parsed and returned as JSON representing an AST, 
that fed back into a subscription port that I then decoded into union types 
.
 

> I don't think a parser is a side-effect. A parser is a pure function from 
> String -> Ast, with no side effects.
>

Technically, no. That's why I was asking about a native module API, since I 
just copied elm-markdown.
 

> The thing about ports for something like this is it feels a bit unnatural 
> to invoke the port resulting in a Cmd. Then you'll need a subscription port 
> to get the result back in, and have that pass it to your update function 
> from where you can take it and place it in the model. That doesn't feel 
> like a good way to call a function : String -> Ast.
>

Well, since there's no official documentation on a native module API, ports 
is what I can rely on. But from a semantics point of view, since I'm 
calling out to something that might have a side effect, it makes sense. 
It's just the mechanics is a bit awkward. I've had the pleasure of swimming 
in his design decisions in Elm so far, and he's built up enough cred with 
me that I think he'll figure something out.

I was just looking for some guidance as to what to implement in pure elm, 
and what to leverage native modules for. Even in other languages where new 
libraries are implemented completely in that language (like ruby, per the 
original post on native modules a year ago), there are libraries that call 
out. The main one that comes to mind is the Linear Algebra Package (LAPACK) 
originally written in Fortran, but most languages that use it now are 
usually just wrappers around it. I just wondered where Elm community drew 
the line.

Wil

-- 
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] width of message history in debugger

2016-12-06 Thread Wil C
Is there a way to expand the width of the message history pane in the 
debugger? I can't seem to see my entire message, since the pane doesn't 
appear to be resizable.

Wil

-- 
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: Stance on native APIs for 0.18?

2016-12-06 Thread Wil C
I'm building a document editor with executable code in it. So far, I have 
SQL embedded in Markdown. 

For markdown, I needed flexibility in changing the output from the standard 
HTML output, like adding extra info around a code block. I looked at 
elm-markdown, and found it didn't have this flexibility. In addition, it 
embedded a minified version of marked.js inside of it. 

Looked into parsing markdown briefly, and discovered it's not even a BNF, 
and would probably spend a lot of time writing the parser. I found 
commonmark.js. 

So now, either I write a ports for commonmark.js, or I write it as a native 
module. I asked about it here 
<https://groups.google.com/forum/#!topic/elm-discuss/Kd53qnKY-io> with no 
answers. 

I decided to write it as a native module with elm-markdown.js as a 
template. It's a bit messy in there, because 1) I'm proving out a concept, 
but also, 2) I'm not sure what is considered good practice. I had looked at 
a few other libs with native modules, and it seemed like they were using an 
API of some sort, rather than directly using namespaces like 
"_elm_lang$virtual_dom$Native_VirtualDom"

That's why I was asking. In cases where it's an integration library, like 
talking to the twitter API, I think it makes sense to write it entirely in 
Elm. Might be boring work, but it's doable. But what about things like 
parsers? If you find a parser in JS (ie. code above a certain complexity 
threshold) for a language, should you try to rewrite it in Elm? My guess is 
ideally, yes. But often times, I'm under a time crunch, or I'm more 
interested in proving out a concept to myself, so diving down to take the 
time to write a parser didn't make sense for me this time.

Wil

On Monday, December 5, 2016 at 9:22:42 AM UTC-8, Richard Feldman wrote:
>
> No new thinking on that as far as I'm aware...what are you looking to 
> build?
>
> On Mon, Dec 5, 2016, 8:37 AM Wil C <iam...@gmail.com > wrote:
>
>> Do you know if there's going to be a guide on native modules? I just used 
>> elm-markdown as a guide, but I saw there were other conventions in other 
>> libraries with native modules.
>>
>> I understand the hesitation in giving a guide on an escape hatch to 
>> native, since people will instinctively reach for it. Just was wondering if 
>> there was new thinking on it.
>>
>>
>> On Monday, December 5, 2016 at 8:19:14 AM UTC-8, Richard Feldman wrote:
>>>
>>> Looking at the evancz/elm-markdown 
>>> <https://github.com/evancz/elm-markdown> parser, that seems like a case 
>>> that warrants it, yeah.
>>>
>> -- 
>> 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/nuR4NnCVcMs/unsubscribe.
>> To unsubscribe from this group and all its topics, 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.


[elm-discuss] Re: Stance on native APIs for 0.18?

2016-12-05 Thread Wil C
Do you know if there's going to be a guide on native modules? I just used 
elm-markdown as a guide, but I saw there were other conventions in other 
libraries with native modules.

I understand the hesitation in giving a guide on an escape hatch to native, 
since people will instinctively reach for it. Just was wondering if there 
was new thinking on it.

On Monday, December 5, 2016 at 8:19:14 AM UTC-8, Richard Feldman wrote:
>
> Looking at the evancz/elm-markdown 
>  parser, that seems like a case 
> that warrants it, yeah.
>

-- 
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: Stance on native APIs for 0.18?

2016-12-05 Thread Wil C
What about for non-trivial things like markdown parsers?

Wil

On Monday, December 5, 2016 at 12:06:42 AM UTC-8, Richard Feldman wrote:
>
> Yeah, my impression is that that post still reflects Evan's thinking on 
> the matter. :)
>

-- 
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: Race condition in textareas?

2016-12-05 Thread Wil C
I just ran into this problem. And the work around was pretty simple, and 
mentioned in a message in this group a while back.

  textarea [
property "defaultValue" (Json.Encode.string model.body)
  , onInput UpdateBody
  , rows (model.cursorAperture * 2)
  , id "edit-glass"
  , class "form-control"] []
]

I used defaultValue instead of value. I think the textarea and the various 
frameworks fight each other when 'value' is used, so you get the jumpiness 
going on. I think it's because Elm is keyed off of 'value' for updates. 
This way, the textarea maintains its own state, and when it changes, it 
doesn't trigger a re-render from Elm for the textarea itself.

On Saturday, December 3, 2016 at 11:08:38 AM UTC-8, Esteban Manchado 
Velázquez wrote:
>
> Hi,
>
> I have a strange, intermittent issue with textareas. It mostly seems to 
> happen in mobile browsers. The issue is that, when editing text *in the 
> middle* of a textarea, as opposed to adding to the end, sometimes the 
> cursor jumps to the end. I assume it's some kind of re-creation of the 
> textarea DOM element.
>
> I have made a simple application with a textarea but that DOES seem to 
> work fine... so I'm wondering if the problem happens because my application 
> is bigger, and I have "subapplications" that use App.map for messages and 
> so on.
>
> Has anyone seen that before? Is it something stupid I'm doing, a bug in 
> Elm, ...? I can make the full source code available if that'll help.
>

-- 
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] Stance on native APIs for 0.18?

2016-12-04 Thread Wil C
I was reading the various message posts, and I happened upon this post on 
the stance of native modules from a year ago:

https://groups.google.com/forum/#!searchin/elm-dev/native$20author$3aeva...@gmail.com/elm-dev/1JW6wknkDIo/H9ZnS71BCAAJ

I was just wondering if there was an updated stance? Or this is pretty much 
the way going forward?

I'm all cool with the stance. But for some libraries, I hesitate to 
reimplement in elm, such as a parser/renderer for markdown or vega. It 
seems non-trivial. And I worry about having to track the upstream changes, 
since I'm neither a markdown for vega expert. I also noticed that the 
standard elm-markdown uses a minified JS version of marked.js in it as a 
native module. Even then, the renderer wasn't implemented in pure Elm. 

So right now, I'm using ports, as suggested, and a native module for 
commonmark.js. It makes some things a bit cumbersome, but it's working out 
so far. Just wanted to know if there were any thoughts from Elm maintainers 
about the topic going forward.

Wil

-- 
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] Should parsing code be integrated into Elm using port, managed effects, or native modules?

2016-11-22 Thread Wil C
I currently have a js library that will parse code and return either the 
html (render) or the AST (abstract syntax tree). The AST action per node is 
modifiable. I'd like use it in the following way:

For a single node type in the AST, I want to process it (rather than just 
rendering it to Html)
For every other node type, I want it to render Html, which the library does 
by default.

I'm curious about how to do the integration with Elm here. Should I use 
ports, managed effect module (like Time module), or a native module (like 
Http module)?

The guide discourages managed effects. If that's the solution here, I'm 
open to doing it.

Writing native modules seem like reaching into private interfaces and will 
cause me trouble down the line when new versions of elm come out. But in 
all the Html and Markdown modules I've seen, it just uses Native modules, 
presumably to avoid pitfall #2 below.

Hence, I think I need to use Ports. The easy part is sending a String of 
code into the port for parsing. I see two pitfalls with this approach:

   1. When I get back the single node type in the AST, I'd need to pass it 
   back to Elm as a JSON, and write a decoder to parse it. That seems like a 
   lot of work (Decoders take me a long time to write).
   2. For AST nodes rendered as Html, if I don't pass them back into Elm, I 
   assume that Elm wouldn't be able to do shadow dom diffing on it for 
   rendering. If I do pass them back into Elm, I'd have to write an Elm 
   Decoder from JSON into Html Msg, and that seems like a lot of work.

So what's the best way to tackle this? Is parsing a side effect? Would it 
make sense if this was a managed effect?

Wil

-- 
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] Sometimes elm-lang.org hangs on "loading..."

2016-11-19 Thread Wil C
Since the update to 0.18, it seems like the web page on elm-lang.org--esp 
the docs pages--seems to hang with "Loading..." when I hit the page. It's 
not a big deal, since I can reload the page, and I get what I want. But it 
seems like a regression, and I didn't know if it was me, or if everyone 
else also sees this? Just bringing it up, if it's something that needed to 
be looked into. 

Wil

-- 
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] Json decoder: converting {type: foo, 0: a, 1: b, 2: c} to { type: foo, children: [a, b, c] }

2016-11-10 Thread Wil C
Hi all,

I've been struggling with this for the better part of today. I find Json 
decoders really hard to grasp, for some reason, especially when there's a 
weird mapping you need to do. My JSON looks like this, and is an abstract 
syntax tree of "select * from submissions where age < 10":

{
"0": {
"0": "select",
"1": [],
"2": {
"type": "SelectList"
},
"3": {
"0": {
"0": "from",
"1": [
{
"0": "submissions",
"1": null,
"2": null,
"3": null,
"4": null,
"5": null,
"type": "TablePrimary_table_or_query_name"
}
],
"type": "FromClause"
},
"1": {
"0": "where",
"1": {
"0": null,
"1": {
"0": [
"age"
],
"1": {
"0": "<",
"1": "10",
"type": "ComparisonPredicatePart2"
},
"type": "ComparisonPredicate"
},
"type": "BooleanFactor"
},
"type": "WhereClause"
},
"2": null,
"3": null,
"type": "TableExpression"
},
"type": "QuerySpecification"
},
"1": null,
"2": null,
"type": "CursorSpecification"
}

I'd like to be able decode it into a node union type and type alias:

type Node =
Empty
  | Node NodeRecord


type alias NodeRecord = {
type' : String
  , primitiveValue: Maybe String
  , children : List Node
  }

Now, because each child of the node is listed as a key-value pair in the 
node itself, I'm not sure how to write the decoder so that each of the 
key-value pairs except "type" are mapped into `children` field of the 
NodeRecord. At the end of post, that code was the best I could come up 
with, but I get an error:

"TypeError: Cannot read property 'tag' of undefined".
function runHelp(decoder, value)
{
switch (decoder.tag) < this is where it fails.
{
case 'bool':
return (typeof value === 'boolean')
? ok(value)
: badPrimitive('a Bool', value);

case 'int':
if (typeof value !== 'number') {
return badPrimitive('an Int', value);


I'm not sure how to debug this, or whether I'm going down the right path. 
Below is the decoder code I have. Can anyone give me a hint? Thanks.

nodeDecoder : Decoder Node
nodeDecoder =
  oneOf [
null Empty
  , string `andThen` primitiveNodeDecoder
  , parentNodeDecoder
  ]

primitiveNodeDecoder : String -> Decoder Node
primitiveNodeDecoder primitive =
  object3 fromFields
(succeed "primitive")
(maybe (succeed primitive))
(succeed [])

parentNodeDecoder : Decoder Node
parentNodeDecoder =
  object3 fromFields
("type" := string)
(maybe ("primitiveValue" := string))
("children" := childrenDecoder)

childrenDecoder : Decoder (List Node)
childrenDecoder =
  customDecoder (dict value) (\nodeDict ->
let
  children = nodeDict |> Dict.remove "type" |> Dict.values
  b = Debug.log "children" children
  combineResults = List.foldr (Result.map2 (::)) (Ok [])
  childDecoder = lazy (\_ -> nodeDecoder)
  results = combineResults (List.map (decodeValue childDecoder) 
children)
  c = Debug.log "results" results
in
  results

-- 
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] How to decode a recursive JSON from a port?

2016-10-05 Thread Wil C
Hi all,

Thanks again for all your help. And when I've asked questions last year.

I have another question. Here's my situation. I want to pass a json from a 
port, and decode the json into records. 

My port:

port parseSuccess : (Json.Encode.Value -> msg) -> Sub msg


When calling it:

app.ports.parseSuccess.send(JSON.stringify(cst.toAst()))

The recursive record:

type alias Node = {
> name : String
>   , children : Children
>   }
>
> type Children =
>   Children (List Node)


The fromJson to decode the Json.

fromJson : Json.Value -> Result String Node
> fromJson json =
> Json.decodeValue nodeDecoder json
>

My decoders:

nodeDecoder : Decoder Node
> nodeDecoder =
>   object2 Node
> ("name" := string)
> ("children" := childrenDecoder )
>
 

childrenDecoder : Decoder Children
> childrenDecoder =
>   customDecoder
> (Json.list nodeDecoder)
> (\children -> Result.Ok <| Children children)


When I run it, I get an error in the Result in "fromJson"
: Err "Expecting an object with a field named `name` but instead got: 
\"{\\\"name\\\":\\\"WhereClause\\\",\\\"children\\\":[{\\\"name\\\":\\\"ComparisonPredicate\\\",\\\"children\\\":[\\\"age\\\",{\\\"name\\\":\\\"ComparisonPredicatePart2\\\",\\\"children\\\":[\\\"<\\\",\\\"10\\\"]}]}]}\""

What's the difference between Json.Encoder.Value and a String? When I'm 
calling the port on the JS side, I'm sending a string from 
JSON.stringify(). It seems like it comes in as Json.Encoder.Value as the 
type, but according to the error, it seems like it's coming in as a string. 
What am I doing wrong?

Wil


-- 
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] What's the convention for modules with more than one word?

2016-10-05 Thread Wil C
Ah, thanks.

On Thursday, September 29, 2016 at 1:10:04 PM UTC-7, Joey Eremondi wrote:
>
> CamelCase in both cases. The file names usually exactly match the module 
> name, with .elm added.
>
> On Thu, Sep 29, 2016 at 1:08 PM, Wil C <iam...@gmail.com > 
> wrote:
>
>> Oddly enough, for the stuff I've written in elm, I've not had to name a 
>> multi-word module.
>>
>> What's the naming convention for multi-word modules? Is it CamelCase for 
>> the module name, but snake_case for the file name? I can't seem to find an 
>> example.
>>
>> Wil
>>
>> -- 
>> 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.


[elm-discuss] More than one argument in the receive port call?

2016-10-03 Thread Wil C
 Hi all,

How do you pass back more than one argument in a receive port call? It says 
to visit http://guide.elm-lang.org/effect_managers/, but there's nothing 
there on the topic. I tried something like this:

Port `parseFailure` has an invalid type.


10| port parseFailure : (String -> Int -> msg) -> Sub msg

^

You are saying it should be:


(String -> Int -> msg) -> Platform.Sub.Sub msg


But you need to use the particular format described here:





-- 
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] What's the convention for modules with more than one word?

2016-09-29 Thread Wil C
Oddly enough, for the stuff I've written in elm, I've not had to name a 
multi-word module.

What's the naming convention for multi-word modules? Is it CamelCase for 
the module name, but snake_case for the file name? I can't seem to find an 
example.

Wil

-- 
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] elm-make behavior different between localhost dev and production

2016-09-29 Thread Wil C
Hi all,

I have a puzzling situation that I hope someone can shed some light on. I'm 
using elm with elixir, and compiling it with elm-brunch. I'm able to 
'brunch build' without a problem locally, but on the remote heroku servers, 
I get the following problem:

remote:Running default compile
> remote:Elm compile: src/rei.elm, in web/elm, to 
> ../static/vendor/rei.js
> remote:*I cannot find module 'Codefragment'.*
> remote:
> remote:Module 'Rei' is trying to import it.
> remote:
> remote:Potential problems could be:
> remote:  * Misspelled the module name
> remote:  * Need to add a source directory or new dependency to 
> elm-package.json
> remote:29 Sep 08:42:47 - error: Compiling of web/elm/src/rei.elm 
> failed. Command failed: ../../node_modules/elm/binwrappers/elm-make --yes 
> --output ../static/vendor/rei.js src/rei.elm
> remote:I cannot find module 'Codefragment'.
> remote:
> remote:Module 'Rei' is trying to import it.
> remote:
> remote:Potential problems could be:
> remote:  * Misspelled the module name
> remote:  * Need to add a source directory or new dependency to 
> elm-package.json
> remote: 


I checked that the source_directories are set. my elm-package.json is:


{
> "version": "1.0.0",
> "summary": "helpful summary of your project, less than 80 characters",
> "repository": "https://github.com/user/project.git;,
> "license": "BSD3",
> 
>
> *"source-directories": ["src"],*
> "exposed-modules": [],
> "dependencies": {
> "elm-lang/core": "4.0.5 <= v < 5.0.0",
> "elm-lang/html": "1.1.0 <= v < 2.0.0"
> },
> "elm-version": "0.17.1 <= v < 0.18.0"
> }


All the elm files are under web/elm/src. my brunch's config files for elm 
is:

  plugins: {
> elmBrunch: {
>   elmFolder: "web/elm",
>   
>
> *mainModules: ["src/rei.elm"  ],*
>   outputFolder: "../static/vendor",
>   executablePath: "../../node_modules/elm/binwrappers"
> },
> babel: {
>   // Do not use ES6 compiler in vendor code
>   ignore: [/web\/static\/vendor/]
> }
>   },


Reading brunch-elm code  
and the 
mainModules should be correct. However, through trial and error, 
"src/rei.elm" fails on production, but not on my local machine. However, 
using "src/*.elm" seems to not fail in production, but while it compiles, 
it doesn't seem to write to the output. 

Has anyone else run into this? It seems like elm-make has a different 
behavior on macos, compared to on heroku.

For now, I'm just committing the generated file to the repo, which works. 
But I'd rather have the file build in production. If someone has something 
to shed the light on this, I'd really appreciate it.

Wil

-- 
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] Making new Cmds

2016-05-25 Thread Wil C
That worked, thanks. I guess I should hold off telling people stuff.

Wil

On Wednesday, May 25, 2016 at 12:00:48 AM UTC-7, Janis Voigtländer wrote:
>
> Task.perform never identity (Task.succeed NewMsg)
>
> with never from 
> http://package.elm-lang.org/packages/elm-community/basics-extra
> ​
>
> 2016-05-25 8:53 GMT+02:00 Wil C <iam...@gmail.com >:
>
>> It turns out it doesn't. What's the correct way to do this?
>>
>> Wil
>>
>> On Tuesday, May 24, 2016 at 10:48:33 AM UTC-7, Janis Voigtländer wrote:
>>>
>>> This is not doing what you almost certainly think it does.
>>> ​
>>>
>>> 2016-05-24 18:44 GMT+02:00 Wil C <iam...@gmail.com>:
>>>
>>>> It's just an aside, in case someone searches for it. Here's how to make 
>>>> new commands:
>>>>
>>>> Cmd.map (\_ -> NewMsg) Cmd.none
>>>>
>>>> It wasn't obvious to me.
>>>>
>>>> Wil
>>>>
>>>> -- 
>>>> 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...@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: Pong example in Elm 0.17

2016-05-18 Thread Wil C
The mario example in 0.17

https://gist.github.com/pdamoc/6f7aa2d3774e5af58ebeba369637c228

On Thursday, May 12, 2016 at 12:59:13 AM UTC-7, Sean Seefried wrote:
>
> Hi all,
>
> I just started using Elm about 2 weeks ago. I had a lot of fun playing 
> with the Pong example and even started making my own game in Elm. I'm a 
> long time Haskell programmer and since Elm is very Haskell-like I've found 
> it very easy to use.
>
> Then Elm 0.17 came out and suddenly Signals are gone. "No problem", I 
> thought, "I'll just look at how Pong is implemented now and update my game".
>
> But then I discovered that the Pong example is now gone. So I decided to 
> look through the new libraries to see how graphics were done now ... and 
> discovered that I couldn't find how to do HTML Canvas-style graphics 
> anymore.
>
> So, my two questions are:
>
> 1. Is the Pong example being rewritten in Elm?
> 2. How do I do HTML canvas-style graphics now? 
>
> Cheers,
>
> Sean
>
> p.s. Please don't take the tone of this post the wrong way. I'm very happy 
> to keep up with Elm as it evolves. I just want to know how to reimplement 
> my game as quickly as possible! :-) 
>

-- 
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: How to implement wrapping components in elm

2016-05-17 Thread Wil C
Daniel,

I think normally, you don't. I think the constraint here is that you need 
to explicitly set the types of each of the sub-components for every 
component that you make for a page. In the example that you give, you'd 
actually need to create 4 types of components: TopLevel, Counter, 
CounterList, and Gif. 

TopLevel component would include CounterList and Gif. And then CounterList 
would contain Counters. It is CounterList's job to dynamically keep track 
of the number of Counters. That way, you don't need a generic component to 
contain an unknown number of things with unknown types. And then if those 
components need to talk to each other (Like once you add 5 or more 
counters, you see a funny cat gif), I believe you can send messages through 
Cmds (in 0.17) or Effects (in <0.17). 

With the hierarchical thinking of laying out components, I found that Thinking 
in React  
helps. 

If you find that you really need the flexibility of having different 
components in a container, it's doable. But it comes at a cost. Generally, 
if you're making a web app of some sort, it's not needed. I cover entity 
component systems recently in another thread, and it's for games.

https://groups.google.com/forum/#!topic/elm-discuss/c9MhBzVPbr8

Wil

On Tuesday, May 17, 2016 at 5:13:56 AM UTC-7, Daniel Kwiecinski wrote:
>
> Hi Elmers,
>
>
> Here is my scenario. Say I have Main.elm which defines main view form my 
> application. I also have bunch of other components (with their 
> corresponding model  and message types) say Counter and Gif. 
> (
> https://github.com/evancz/elm-architecture-tutorial/blob/master/nesting/Gif.elm
> )
> (
> https://github.com/evancz/elm-architecture-tutorial/blob/master/nesting/Counter.elm
> )
> Now I'd like to create new generic component which as a parameter (initial 
> value of its model?) takes list of any type of component (say two counters, 
> then one gif and another three counters) and wraps them into some 
> decorating html.
> The scenario serves as a illustration of the question, how do I implement 
> components which can wrap lists of arbitrary component types.
>
> --
> Regards,
> Daniel
>

-- 
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: How to map over a list of entities that are different types?

2016-05-16 Thread Wil C
So, I came up with a solution that seems to work. As reference (and for 
others), I did reference work on Entity-Component Systems mentioned in this 
group before.

https://gist.github.com/TheSeamau5/8d7fac9f1937f0bab317
https://gist.github.com/TheSeamau5/ec9695232ae919185f4d

And I found Chris Granger's post quite 
helpful: www.chris-granger.com/2012/12/11/anatomy-of-a-knockout/

I decided to model a generic entity as:

// entity.elm

type alias ID = Int

type alias Model = {
id : ID
  , components : List Component
  }

With the components as a type:

// entity.elm
type Component =
Spatial Component.Spatial.Model
  | Corporeal Component.Corporeal.Model
  | Label Component.Label.Model
  | Viewable ComponentView
  | Gravitate Component.Gravitate.Model

type alias ComponentView = {
func : Model -> Form
  }

And the Spatial component model would contain fields that had to do with 
spatial orientation of the entity, modeled as:

// components/spatial.elm
type alias Model = {
mass : Float
  , forces : List Vec.Vec
  , pos : Vec.Vec-- in units
  , vel : Vec.Vec-- in units / centiseconds
  , acc : Vec.Vec-- in units / centiseconds ** 2
  , heading : Float
  }

So in declaring an instance entity, such as a cat, I modeled it as:

// entity/cat.elm
init : Entity.ID -> Entity.Model
init id = {
id = id
  , components = [
  Entity.spatial 50 (100, 0)
, Entity.corporeal (45, 45) Color.orange
, Entity.viewable view
, Entity.gravitate Component.Gravitate.ToEarth
]
  }

where view() was another method with the signature view : Model -> Form

What is Entity.spatial? Well, it's just:

//entity.elm
spatial : Float -> Vec -> Component
spatial mass pos =
  Spatial <| Component.Spatial.init mass po

So entity.elm has some functions that delegate to the specific component 
being created, and just tacks on the type in front.

How do we get at a particular component type in a list of components?

getSpatial : Model -> Maybe Component.Spatial.Model
getSpatial model =
  List.filterMap (\component ->
case component of
  Spatial spaceModel ->
Just spaceModel
  _ ->
Nothing
  ) model.components
  |> List.head

Unfortunately, this needed to be repeated for all other components. I don't 
know of a way to pass in a type and use it in the branches of a case 
expression.

But sometimes, you don't just want to get the component, you want to 
replace it. Learning the lesson from functors, I added a filterMap for 
entity, treating it as a container.

filterMapSpatial : (Component.Spatial.Model -> Component.Spatial.Model) -> 
Model -> Model
filterMapSpatial func entity =
  { entity |
components = List.map (\component ->
case component of
  Spatial space ->
Spatial (func space)
  _ ->
component
  ) entity.components
  }

So when I update and step through the model with a dt tick, I do:

//main.elm
step : Float -> Model -> Model
step dt model =
  model
  |> boundFloor
  |> gravity dt
  |> newtonian dt
  |> clearForces

where each one of those functions changes the model somehow. In newtonian, 
it maps over all entities and calls newtonian on each entity.

// main.elm
newtonian : Float -> Model -> Model
newtonian dt model =
  map (Entity.newtonian dt) model

it calculates the new position based on the velocity. It calculates 
velocity based on the total acceleration. And it calculate the total 
acceleration based on all the forces acting on it. So even though all the 
entities have different components, I'm able to call newtonian on each 
entity, and filterMapSpatial will act on a spatial component, if it can 
find one, and update it.

// entity.elm
newtonian : Float -> Model -> Model
newtonian dt entity =
  filterMapSpatial (\space ->
let
  acc = Component.Spatial.totalAcc space
  space2 = Component.Spatial.vel (space.vel |+ acc .* (dt / 10)) space
in
  Component.Spatial.pos (space2.pos |+ ((space.vel |+ space2.vel) .* 
(0.5 * (dt / 10 space2
  ) entity

And in that way, I can call newtonian on every entity, regardless of what 
components it has, because filterMapSpatial looks for a spatial component 
in an entity's component list, and only acts to replace it if it can find 
one. 

And that's how I got around overloading and polymorphism. The full code 
(work in progress, as of this posting) is here 
<https://github.com/iamwilhelm/bayes-cat/tree/796542f8789726a797a268bf521c2a8c5e56b64a>.
 
The downside is that every time you add a component, you have to add 
accessor and filterMap functions for each component.

Hope that helps someone.

Wil

On Tuesday, May 10, 2016 at 11:56:44 PM UTC-7, Wil C wrote:
>
> Thanks so far for the help that elm community has given lately. Really 
> appreciated. :)
>
> I've been in the middle of writing a simple game in Elm. However, I'm 
> running into a

[elm-discuss] How to render at a lower fps in 0.17?

2016-05-16 Thread Wil C
I've made the switch to 0.17, and I've also followed along with the mario 
example . 
I can see how to get the delta, but it's locked in at around 60 fps with a 
subscription like "AnimationFrame.diffs Tick". How do I subscribe to 
AnimationFrame.diff with a lower framerate? It doesn't looks like I can use 
Time.every.

Wil 

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