Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upTime type alias defined in different places #412
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mgold
Sep 28, 2015
Contributor
Task does not expose the Time alias, and the compiler can figure out what type it wants, so I don't see much of a downside to the current arrangement. I suppose I could get behind placing it in Basics, if that wouldn't make Task and Time much more complicated, but again I don't see the need to.
|
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Sep 28, 2015
Contributor
It's not a big issue, of course. More a matter of principle and style and looking into possible futures. Consider:
- At some point it is decided that
Timeshould not beFloat, but maybeIntor even some completely other type. Then there will be two places where this has to be changed. No big problem, I'll grant, because at least these two places are both in the same packagecore, so the compiler would likely catch this before release. (Actually, it would only catch it if there is some code incorein whichTask.TimeandTime.Timeare unified. It might be the case that there is no such code. Then,corewould compile just fine and could be released, but clients couldn't use the modules as intended, because they wouldn't be able to passTimes created with functions from theTimemodule to functions from theTaskmodule that expect aTime.) - Or (and more likely, since it has always been said that this is coming), at some point something like Haskell's
newtypefeature is implemented via uniontypes with exactly one constructor in Elm. Then certainly we will want to seetype Time = Time Float(we should want this already now, for the same type safety reasons that usually motivatenewtypein Haskell libraries). And then your argument vanishes. We will then have to put theTimedefinition in exactly one place. Which, at that time in the future, will force refactoring of more code than it does today.
So I stand with: This should be done. Better now than later.
Relatedly, this was done.
|
It's not a big issue, of course. More a matter of principle and style and looking into possible futures. Consider:
So I stand with: This should be done. Better now than later. Relatedly, this was done. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Sep 29, 2015
Member
I think your point number 2 is wrong. I want to be able to say (4 * hour) so wrapping things up with type Time = Time Float seems bad given how certain things work now. It'd at least be a major undertaking to get this working nicely again.
I think point 1 is pretty weak. I think we can remember this kind of thing. If we don't remember it, we can fix it really easily.
|
I think your point number 2 is wrong. I want to be able to say I think point 1 is pretty weak. I think we can remember this kind of thing. If we don't remember it, we can fix it really easily. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Sep 29, 2015
Contributor
Now that's a valid point, against type Time = Time Float. I had forgotten that the stuff like hour in Time are just constants, not functions like hours : number -> Time. So yes, if we want to write stuff like (4 * hour), and don't have type classes, wrapping Time as a newtype style thing is not an option.
And yes, as I already granted, the other point about potentially conflicting changes is not a major thing. It's at least likely it won't hurt much.
Anyway, I still think it would make sense to put Time into Basics. Isn't Time meant to be the "standard" type for this in Elm? We don't have to import module String to get Elm's String type into scope (same for lists). So why do we have to import module Time to get Elm's Time type into scope? Ultimately, the current setup tempts people to just use Float instead of Time in their own type signatures even where Time would be appropriate and even if they eventually want to pass those values on to something like Task.sleep. (They are tempted to do that because thus they can save the import Time exposing (Time) line.) Having Time defined in Basics, and thus always in scope, would remove that temptation, which would result in better user code.
The fact that we wouldn't have two definitions of Time in core would be a nice side effect.
But feel free to close this issue if you really prefer the current setup.
|
Now that's a valid point, against And yes, as I already granted, the other point about potentially conflicting changes is not a major thing. It's at least likely it won't hurt much. Anyway, I still think it would make sense to put The fact that we wouldn't have two definitions of But feel free to close this issue if you really prefer the current setup. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Sep 29, 2015
Member
I think having two is dumb as well, so to get back on track: is the proposal to put it in Basics now? The other options are filtered out?
|
I think having two is dumb as well, so to get back on track: is the proposal to put it in |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Yes, I think so. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Sep 29, 2015
Member
Let's either open an issue that describes the refined idea clearly or do a PR.
|
Let's either open an issue that describes the refined idea clearly or do a PR. |
evancz
closed this
Sep 29, 2015
jvoigtlaender
referenced this issue
Sep 29, 2015
Closed
Move Time type alias(es) to Basics module #415
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Sep 29, 2015
Contributor
I've prepared such a PR: https://github.com/elm-lang/core/pull/415. (I've checked it locally with an example program that uses both Time.second and Task.sleep as well as an explicit type signature including Time. All I needed to do to make the program work with the revised core as per that pull request was to remove Time from the list in my import Time exposing (Time, ...) line. If I hadn't been using Time.second in that program, I could now have removed the whole import Time ... line.)
|
I've prepared such a PR: https://github.com/elm-lang/core/pull/415. (I've checked it locally with an example program that uses both |
jvoigtlaender commentedSep 26, 2015
There is one definition of
in
Time.elmand an identical one inTask.elm.This seems conceptually wrong, and potentially hurtful for later developments. So I think it would be better to have that definition only in one place, and import it everywhere else it is needed.
What would be options for this?
Timewould beTime.elm, but that is problematic, sinceTime.elmimportsSignal.elm, which importsTask.elm, so havingTask.elmimportTime.elmwould lead to a cycle.Task.elmandTime.elmcould import it from there. It seems a bit odd, though, to have the primary definition ofTime(and the place where it is documented) be inTask.elm.Basics.elmand be imported intoTime.elmandTask.elmfrom there.Is anything wrong with the third option? It would essentially give
Timethe same status asInt,Float,Stringas pre-defined Elm types. It seems that is an okay thing to happen.