On Mon, Jun 12, 2017 at 8:08 AM, Evan <[email protected]> wrote:
> Syntax
>
> I was formerly somewhat keen on having special syntax for other
> collections. For example, OCaml allows you to say [| 1, 2, 3 |] to create
> an array. Hassan made a really nice proposal
> <https://github.com/elm-lang/elm-plans/issues/12> to have it be #[ 1, 2,
> 3 ] back in 2015. Since then I realized you can do the following:
>
> a = Array.fromList
> s = Set.fromList
> d = Dict.fromList
>
> array =
> (a[ 1, 2, 3 ])
>
> set =
> (s[ 1, 2, 3 ])
>
> dict =
> (d[ 1 => "Tom", 2 => "Sue", 3 => "Jane" ])
>
> (=>) = (,)
>
> This is 1 or 2 characters off all the proposals out there, and it is
> visually much nicer in my opinion.
>
This might sound silly but wouldn't it be possible to have the same syntax
and let the programmer make the type concrete with usage?
array : Array
array = [1, 2, 3]
list : List
list = [1, 2, 3]
I'm asking because we already have a similar situation with `number` where
one ca declare both Int and Float the same way and the compiler is able to
figure out the actual type.
Maybe something similar can be done for dictionaries/records too:
record : Record
record = { field = "value"}
dict : Dict
dict = { key : "value"}
set : Set
set = {1,2}
The main advantage of a dictionary syntax like above is that it is familiar
for people coming from python/javascript.
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.