Proposal: shorthand record names

103 views
Skip to first unread message

Zane Hitchcox

unread,
Sep 24, 2016, 12:46:55 PM9/24/16
to Elm Discuss

Shorthand property names like in javascript


These are a great feature, and maybe elm can steal something from javascript for a change.


Like I see no reason for this overly-verbose syntax:


main : Program Never
main =
    Html.App.program
        { init = init
        , view = view
        , update = update
        , subscriptions = subscriptions
        }

Joey Eremondi

unread,
Sep 24, 2016, 1:27:07 PM9/24/16
to elm-d...@googlegroups.com

Can you give a concrete example of what this would look like in Elm? Are you sure this is compatible with type inference?


--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave Thomas

unread,
Sep 24, 2016, 2:38:16 PM9/24/16
to Elm Discuss
I don't think its overly verbose as it is, ocaml has a feature called field pruning:

When the name of a variable coincides with the name of a record field, OCaml provides some handy syntactic shortcuts. For example, the pattern in the following function binds all of the fields in question to variables of the same name. 
 
let host_info_to_string { hostname; os_name; cpu_arch; timestamp; _ } =
     sprintf
"%s (%s / %s) <%s>" hostname os_name cpu_arch
       
(Time.to_string timestamp)

 

On Saturday, September 24, 2016 at 6:27:07 PM UTC+1, Joey Eremondi wrote:

Can you give a concrete example of what this would look like in Elm? Are you sure this is compatible with type inference?

On Sep 24, 2016 10:46 AM, "Zane Hitchcox" <zwhit...@gmail.com> wrote:

Shorthand property names like in javascript


These are a great feature, and maybe elm can steal something from javascript for a change.


Like I see no reason for this overly-verbose syntax:


main : Program Never
main =
    Html.App.program
        { init = init
        , view = view
        , update = update
        , subscriptions = subscriptions
        }

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

Janis Voigtländer

unread,
Sep 24, 2016, 3:40:38 PM9/24/16
to elm-d...@googlegroups.com
That feature, for pattern matching, Elm already has.

OvermindDL1

unread,
Sep 25, 2016, 4:06:32 PM9/25/16
to Elm Discuss
OCaml also has the feature he is asking for too.  A complete example with inline typing as an example:
```ocaml
type myRecord = {
  someInt : int;
  someStr : string;
  someFlt : float;
  }

let createMyRecord : int -> string -> float -> myRecord =
fun someInt someStr someFlt ->
  { someInt; someStr; someFlt }

let myRecordTest =
  createMyRecord 42 "Hello World" 6.28

let () = Js.log myRecordTest
```
See the function `createMyRecord`.
Reply all
Reply to author
Forward
0 new messages