On Wednesday, February 15, 2017 at 10:19:34 PM UTC, Max Goldstein wrote:
> 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.
Yes, I did in fact start out with Rectangle -> a. The reason I generalized 
it a bit more, even though I only have the 'rect' field, is because I am 
going to add some more fields to the WithPosition type. I also need a 
yOffset : Float field, since some of my UI elements are positioned absolute 
wrt to the page body, and some are positioned fixed. elm-dom gives me the 
absolute position wrt to the body, so I also need to factor in the body 
scroll offset to position the fixed UI elements.

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

Similarly, you could argue that { a | fieldICareAbout : Int } -> Thing is 
no less expressive than Int -> Thing. It gets more usefull when you have >1 

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

Thanks for your thoughts, and yes this is more readable I agree. I was 
really just trying to explore all the options and find out what extensible 
records might help me with. They are quite difficult to understand and its 
easy to be lulled into thinking they provide sub-typing when they do not. 
I'll see if I can contribute something to the FAQ or community docs to 
explain their limitations to the unwary.

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.

Reply via email to