Hi, I haven't given it too much though, but I do think there is some very nice benefits to using single constructor union types. In you case, you might avoid some of the noise by adding helper functions to work on values of the type (maybe you need a mapFoo helper function). I found this blog post quite enlightening : https://robots.thoughtbot.com/lessons-learned-avoiding-primitives-in-elm
cheers - magnus On Monday, 16 January 2017 09:40:13 UTC+1, Austin Bingham wrote: > > I recently had to chase down a bug where I was calling a function with the > arguments in the wrong order. The function's declared argument types were > each an alias for string, so the compiler happily let me swap them. In > order to avoid this in the future, I'm experimenting with using > single-constructor union types in place of aliases, e.g. instead of "type > alias Foo = String" I'm using "type Foo = Foo String". > > This seems to work well for helping me enforce the kind of type safety I'm > looking for. However, it seems to force me to do a lot more > de/restructuring of function arguments, and it feels a bit graceless. For > example, a (contrived) function that was originally like this: > > aFunc : Foo -> Foo > aFunc f = > let > x = somethingWithAString f > in > somethingWithAFoo x f > > becomes: > > aFunc : Foo - > Foo > aFunc (Foo f) = > let > x = somethingWithAString f > in > -- Have to "repack" f into a Foo > somethingWithAFoo x (Foo f) > > That is, if I want to thread something of type "Foo" through calls while > also using its data, I have to "repack" it. > > So my question is: are there better ways to do this? Are there better > patterns for a) adding the type-safety I want while b) avoiding the extra > noise? I know some languages (e.g. clojure) let you destructure bindings > *and* bind a name to the un-destructured thing. Something like that might > help. > > Any advice (including "you're doing it wrong!") would be appreciated. > > Austin > -- 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.