Re: [elm-discuss] Is type inference in Elm fully decideable?

2017-02-15 Thread Max Goldstein
I honestly don't know if your code "should" typecheck or not, but if it 
did, it wouldn't do anything more than what you already have. The function 
you pass would only have access to the rect field. I think this code would 
be simpler, and no less expressive, if the function argument was Rectangle 
-> a. The fact that it's wrapped with some arbitrary fields is mixing 
concerns.

I anyone using extensible records much?


I don't think people are using extensible record type aliases much. The { a 
| fieldICareAbout : Int } -> Thing pattern is useful, though. (For example, 
to call a view helper with the whole model but guarantee that it can't look 
at certain fields.)

Nesting these field definitions makes the code a lot less readable then 
just listing the records exactly. Try to make your type definitions more 
explicit, and use your functions signatures to abstract away some of the 
details.

State.mapPosition : (Rectangle -> a) -> State -> Maybe a
State.updatePosition : (Rectangle -> Rectangle) -> State -> State

-- 
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] Is type inference in Elm fully decideable?

2017-02-15 Thread 'Rupert Smith' via Elm Discuss
On Wednesday, February 15, 2017 at 8:49:13 PM UTC, Rupert Smith wrote:
>
> This would seem to make extensible records a lot less useful than they 
> could be. Is this one of those cases where an existential qualifier would 
> be needed to specify the type of the function? Or is this in fact a case 
> that could be typed in Elm without problem and that the type checker should 
> accept?
>

Or to put it another way, is this a case that could type check just fine 
and not lead to a runtime error in the program, but is not allowed because 
it would break the type inference algorithm?

If it can both type check and infer, then it should be allowed.

-- 
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: Is type inference in Elm fully decideable?

2017-02-15 Thread 'Rupert Smith' via Elm Discuss
On Friday, February 10, 2017 at 12:30:22 PM UTC, Rupert Smith wrote:
>
> As I understand it, Elm uses a different extensible record type to that of 
> OO languages with full-blown sub-typing?
>

I anyone using extensible records much? It would be nice to peek at some 
code and see how they are being used. 

-- 
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] Is type inference in Elm fully decideable?

2017-02-15 Thread 'Rupert Smith' via Elm Discuss
On Friday, February 10, 2017 at 3:26:38 PM UTC, Joey Eremondi wrote:
>
> So, Elm lets you do a forall over the rest of a record.
>
> {a | x : Int} -> Int says this function accepts any record that has an x 
> Int field.
>

I am trying to build a model with states, such that fields are only 
available that are actually needed in the relevant state. The model is like 
this:

type alias WithPosition a =
{ a | rect : Rectangle }


type alias WithValue a =
{ a | value : String }


type State
= Hidden
| Aware (WithPosition {})
| Active (WithPosition (WithValue {}))
| Inactive (WithPosition (WithValue {}))
 

It can be convenient to have functions to work on fields in the model, only 
when the state is such that those fields are available. Here is one such 
function:

mapWhenWithPosition : (WithPosition {} -> a) -> State -> Maybe a
mapWhenWithPosition func state =
case state of
Aware { rect } ->
Just <| func { rect = rect }

Active { rect } ->
Just <| func { rect = rect }

Inactive { rect } ->
Just <| func { rect = rect }

_ ->
Nothing

So when in a state that is 'positioned' this function lets me apply a 
function to the position and return the result in a Just, otherwise 
Nothing. Makes it easy to have a UI component that will only appear in 
certain states, for example.

What I don't understand is why this fails to type check:

mapWhenWithPosition : (WithPosition b -> a) -> State -> Maybe a
mapWhenWithPosition func state =
case state of
Aware rect ->
105:Just <| func rect

Active rect ->
Just <| func rect

Inactive rect ->
Just <| func rect

_ ->
Nothing

Complains that:

The argument to function `func` is causing a mismatch.

105| func rect
  
Function `func` is expecting the argument to be:

WithPosition b

But it is:

WithPosition {}

I marked in which line is 105 above. The function WithPosition b -> a is 
general enough to handle a WithPosition {}, but I seem to be only able to 
use it where it fully matches.

This would seem to make extensible records a lot less useful than they 
could be. Is this one of those cases where an existential qualifier would 
be needed to specify the type of the function? Or is this in fact a case 
that could be typed in Elm without problem and that the type checker should 
accept?

Or perhaps there is some other way of writing what I want?

Inactive { rect } ->
Just <| func { rect = rect }

Isn't too bad, but it gets a lot worse when there are lots more fields and 
you are having to deconstruct then reconstruct the same record:

SomeStatate { field1, field2, ..., fieldn } ->
Just <| func { field1 = field1, field2 = field2, ..., fieldn = 
fieldn }


-- 
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] New to Elm, need help understanding type Node msg = Node in source code

2017-02-15 Thread Joey Eremondi
1. In node, the msg parameter is for the types of messages the node can
emit. So if you have a text-box that emits messages when its value changes,
it could have type "Node String".

2. The "type Node msg = Node" is really just some hackery to get things
working with Native. It's just declaring to Elm that there is a type called
Node with a parameter msg. The right hand side is just there because
something has to be there: it's declaring a constructor "Node" which takes
no arguments, but this never gets used, since actual Node values are
produced in Native code.

3. The type "String -> Json.Value -> Property msg" means that, if you give
this function a string and a Json.Value, it will give you a value that can
typecheck against any type of "msg" it needs to. Basically, this means that
the function doesn't actually do anything with the type parameter, so it
will work for any type you give it. This lets you use it in any context you
need.

Native is really quite hackish: it's literally just making the calls to the
given JavaScript, and is completely unchecked, which is why it's intended
for Elm's internal use only. Nothing too fancy is going on, it's just doing
what's necessary to please the Elm type-checker, while injecting JS code.

On Wed, Feb 15, 2017 at 10:31 AM, Will Tian  wrote:

> Hi,
>
> I'm trying to understand how the Html module works. I see many methods
> with return type Html msg, which is a type alias for Node msg.
>
> After tracking down the source code and reading into it, I am confused by
> the following line:
>
> type Node msg = Node
>
> what is the purpose of the above line?
>
> Furthermore, I don't understand the use of the type parameter msg.
>
> For example I can see that type Property msg = Property
>
> and
>
> property : String -> Json.Value -> Property msg
> property = Native.VirtualDom.property
>
> when looking into the implementation of VirtualDom.property, I see
>
> function property(key, value)
> {
> return {
> key: key,
> value: value
> };
> }
>
> Does that mean the return value of calling: property "className"
> (Json.string "myClass") is of type Property msg where msg = { key:
> "className", value: "myClass" }?
> does the property function actually use a type constructor and return the
> type?
>
> Thanks in advance.
>
>
> --
> 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] New to Elm, need help understanding type Node msg = Node in source code

2017-02-15 Thread Duane Johnson
On Wed, Feb 15, 2017 at 11:31 AM, Will Tian  wrote:

> type Node msg = Node
>
> what is the purpose of the above line?
>

I think it's a placeholder type that is not handled in Elm proper, but by
the compiler itself. See
https://groups.google.com/forum/#!searchin/elm-discuss/type$20elm$20compiler$20placeholder%7Csort:relevance/elm-discuss/kfOabaehLNU/IAviSncEEwAJ

-- 
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] New to Elm, need help understanding type Node msg = Node in source code

2017-02-15 Thread Will Tian
Hi,

I'm trying to understand how the Html module works. I see many methods with 
return type Html msg, which is a type alias for Node msg. 

After tracking down the source code and reading into it, I am confused by 
the following line: 

type Node msg = Node

what is the purpose of the above line? 

Furthermore, I don't understand the use of the type parameter msg.

For example I can see that type Property msg = Property

and 

property : String -> Json.Value -> Property msg
property = Native.VirtualDom.property

when looking into the implementation of VirtualDom.property, I see 

function property(key, value)
{
return {
key: key,
value: value
};
}

Does that mean the return value of calling: property "className" 
(Json.string "myClass") is of type Property msg where msg = { key: 
"className", value: "myClass" }?
does the property function actually use a type constructor and return the 
type?

Thanks in advance.


-- 
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] Problem running from .js file

2017-02-15 Thread OvermindDL1
Well XHTML is XML, and if you mark the webpage as XHTML by having the XML 
DOCTYPE (absolutely required) and have a correct xmlns attribute in the 
 (also absolutely required) then it would likely do what you expected.

However, HTML5 is not even remotely XHTML (much as I wish XHTML took over, 
regular parsing is so much easier than the horror that is HTML4/5) as not 
only does it allow some tags to not have an ending tag, it mandates it in 
some places, and forces you to make explicit ending tags even on things 
that never have content.  Sadly, HTML5 is where all development is being 
done, XHTML is dead and missing features now.


On Tuesday, February 14, 2017 at 11:55:20 PM UTC-7, Fabian B wrote:
>
> Thank you.
> Apparently [X]HTML is not XML.
>
> On Tuesday, February 14, 2017 at 6:26:58 PM UTC+2, Peter Damoc wrote:
>>
>> main_js.html is invalid 
>>
>> you need 
>> 
>> not 
>> 
>>
>>
>>
>>
>> On Tue, Feb 14, 2017 at 1:13 AM, Fabian B  wrote:
>>
>>> I created a github project that shows my problem:
>>> https://github.com/fabian20ro/elm-sample - see the readme links...
>>>
>>> How should I change the main_js.html to properly use what elm-make 
>>> --output main.js produced?
>>> I'm really puzzled since eveywhere I look I see exactly this example. I 
>>> assume since everyone is giving it, it should work for everybody else?!
>>>
>>> Thanks for the 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...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -- 
>> 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.