Re: [elm-discuss] Re: Unit Types : A Radical Proposal

2016-08-04 Thread John Bugner
I just realized that Elm already uses this strategy... with `Color`! It has two constructors: RGBA and HSLA ( https://github.com/elm-lang/core/blob/master/src/Color.elm ), but neither is exported. This forces the user to use the various 'creation' functions to create one (

[elm-discuss] Re: Unit Types : A Radical Proposal

2016-07-30 Thread Job van der Zwan
On Thursday, 28 July 2016 20:42:44 UTC+2, John Bugner wrote: > > (5) Perhaps compound unit types like "Time^2" would be supported, so a > "Time * Time" would yield "Time^2", "Time * Float" would yield "Time", and > "Time * Length" would yield just that: "Time * Length". ("Force" would be > an

[elm-discuss] Re: Unit Types : A Radical Proposal

2016-07-29 Thread Max Goldstein
Just be careful with (:::) in particular. Some other libraries already define it, and there's currently no good way to resolve conflicts. -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails

[elm-discuss] Re: Unit Types : A Radical Proposal

2016-07-29 Thread John Bugner
Btw, when using (:::) this way, it's nice to set the operator precedence to something lower than 9 so you can say `2 * 5 + 3 ::: radians` without having to put brackets around the numbers. I think `infix 5 :::` gives the right precedence; Looking at the core docs (

[elm-discuss] Re: Unit Types : A Radical Proposal

2016-07-29 Thread John Bugner
I like the clever use of the (:::) function to make its function argument (somewhat) look like a type. On Friday, July 29, 2016 at 11:48:26 AM UTC-5, Anton Lorenzen wrote: > > I just created a small library for this: > https://github.com/anfelor/elm-units > > It allows for time to be used like

Re: [elm-discuss] Re: Unit Types : A Radical Proposal

2016-07-29 Thread Duane Johnson
On Fri, Jul 29, 2016 at 10:48 AM, Anton Lorenzen wrote: > I just created a small library for this: > https://github.com/anfelor/elm-units > > It allows for time to be used like this: > Units.Time.every (30 ::: milliseconds) Tick > Neat! I'm surprised at what can be done with

[elm-discuss] Re: Unit Types : A Radical Proposal

2016-07-29 Thread OvermindDL1
Yep, that is why I like the style that you can do with current code. :-) On Friday, July 29, 2016 at 6:35:46 AM UTC-6, John Bugner wrote: > > Also, thinking about this further, any definition of conversions between > types is probably best expressed as a function, because a conversion is not >

[elm-discuss] Re: Unit Types : A Radical Proposal

2016-07-29 Thread John Bugner
>This would be a nice fix to the Radians / Degrees issue too. Every language seems to settle on one or the other as "the base unit" but newcomers have to learn the assumption or face bad accidental outputs. Yes, `degrees`, `radians`, and `turns` in `Basics` suffer the same problem. >F# is kind

[elm-discuss] Re: Unit Types : A Radical Proposal

2016-07-28 Thread OvermindDL1
Could possible do it 'now' with ```elm type Time = Time_Value Float milliseconds m = seconds <| m/1000 seconds s = Time_Value s minutes m = seconds <| m*60 from_json json = Json.Decode.decodeString Json.Decode.float json |> Result.map (\t -> Time_Value t) to_seconds (Time_Value t) = t

Re: [elm-discuss] Re: Unit Types : A Radical Proposal

2016-07-28 Thread Joey Eremondi
There is also some prior art with Haskell for this: https://hackage.haskell.org/package/uom-plugin https://hackage.haskell.org/package/units https://hackage.haskell.org/package/Measure On Thu, Jul 28, 2016 at 12:33 PM, Duane Johnson wrote: > > On Thu, Jul 28, 2016

Re: [elm-discuss] Re: Unit Types : A Radical Proposal

2016-07-28 Thread Duane Johnson
On Thu, Jul 28, 2016 at 1:11 PM, art yerkes wrote: > F# is kind of radical in that it has units. > > https://fsharpforfunandprofit.com/posts/units-of-measure/ > Wow, very neat! I like that F# keeps the units after the number, actually adding to readability. -- You

[elm-discuss] Re: Unit Types : A Radical Proposal

2016-07-28 Thread art yerkes
F# is kind of radical in that it has units. https://fsharpforfunandprofit.com/posts/units-of-measure/ It's not perfect, but it could serve as a starting point for evaluating different ways of having units as part of a language. On Thursday, July 28, 2016 at 11:42:44 AM UTC-7, John Bugner