In the previous posting there is a bug -- I should simply use

e = ...

instead of

e = f ...

If you want to make the previous write up work, then you need 

f : X -> E 
and 
... is of type X

rather than the following which is a mistake.

f: E  -> X
and
... is of type E



On Tuesday, August 2, 2016 at 9:05:50 PM UTC-4, Ambrose Laing wrote:
>
> You're right that what I wrote earlier has no way to deal with a Maybe 
> field.  I think it could be generalized to handle Maybe fields, but then we 
> could also think of something that is neither a record nor a Maybe of a 
> record, ...
>
> Anyway, it is not at all pretty but here is a quick idea.  First let me 
> summarize the previous idea using the notation that works best for Maybes:
>
> Suppose that 'a' is of type A, a record, which contains a field called b 
> of type B, which is a record, which contains a field called c which is also 
> a record of type C, which contains a field called d, which is also a record 
> of type D, which contains a field called e, of any type E, and that f is a 
> function of type f : E -> X where X is any type.  Also suppose that ... is 
> an arbitrary elm expression of type E.
>
> Then what I wrote before suggests that we can write:
>
> a.b.c.d.e : E
>
> and, since
>
> a.b.c.d : D
> we can write
> { a.b.c.d | e = f ... } : D  -- where ... is any elm expression which is a 
> valid argument for f.
>
> Also, we have
>
> a.b.c : C
> as well as
> { a.b.c | d.e = f ... } : C
>
> and so on.  So I like this notation up until this point -- it is exactly 
> as I described in my previous post.  However in what follows, I hope to 
> show that adding Maybe's is possible but rather ugly, and while I think it 
> is possible I don't recommend it.  It is just a mental experiment.
>
> In Swift there is a ? operator for dereferencing fields conditionally.
>
> So if everything is just as described above except that c is of type Maybe 
> C, where C is a record type as described above, then we can write this in a 
> similar style to Swift:
>
> a.b.c?.d.e : Maybe E
>
> meaning that if the value of a.b.c is (Just cValue), then a.b.c?.d.e is 
> (Just cValue.d.e)
> but
> if a.b.c is Nothing, then a.b.c?.d.e is Nothing.
>
> Similarly we could have
>
> a.b.c?.d : Maybe D
>
> with the obvious semantics.
>
> However a.b : B
>
> and a : A
>
> I am not a Swift person, but based on my limited understanding of that 
> language, that is what their ? dereference operator means.  Anyone please 
> correct me here.
>
> And if that syntax were ever to find its way into elm (I'm not suggesting 
> that it should, but just addressing this very specific hypothetical 
> question of how it would work with this possible record syntax): then we 
> could also have expressions like this:
>
> { a.b.c?.d | e = f ... } : Maybe D
>
> And this would be 
>
> Just { cValue.d | e = f ... }
>
> if c is (Just cValue), but it would be Nothing if c is Nothing.
>
> Similarly you could have:
>
> { a.b | c?.d.e = f ...} : B
>
> meaning the value of type B in which c.d.e is set to (f ...) if c is (Just 
> cValue) but in which nothing changes if c is Nothing.
>
> It is crazy but it looks well-defined to me.  Caveat I am not a 
> programming languages person.
>
> Having said all this, my instinct is that mixing record syntax with ? 
> dereference is rather unwieldy.  And I would not recommend that we go that 
> far.  Just my opinion.  However I hope that just the records of records of 
> records aspect gets some consideration. :-)
>
>

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

Reply via email to