Like always, not that much has really changed. To make the process as smooth as possible, this document outlines all the things you will want to do to use 0.18.
- Update
elm-package.json
- List Ranges
- No More Primes
- Backticks and
andThen
- Renamed Functions in Core
- Package Changes
A lot of this can be done automatically with elm-upgrade
, so check it out after reading through this document!
So the first thing you want to do is update your elm-package.json
file. The only tricky thing is that the HTTP package moved:
evancz/elm-http
=>elm-lang/http
From there, here is an elm-package.json
that has been properly updated:
{
"version": "1.0.0",
"summary": "let people do a cool thing in a fun way",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"src"
],
"exposed-modules": [],
"dependencies": {
"elm-lang/core": "5.0.0 <= v < 6.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0",
"elm-lang/http": "1.0.0 <= v < 2.0.0",
"evancz/elm-markdown": "3.0.1 <= v < 4.0.0"
},
"elm-version": "0.18.0 <= v < 0.19.0"
}
The only changes should be in the dependencies
and elm-version
fields where you need to update constraints.
The easiest way to get this all set up is to use elm-upgrade
, but you can also:
- Update
elm-version
by hand. - Remove everything from
dependencies
by hand. - Install what you need with
elm-package install elm-lang/core
one-by-one.
The [1..5]
syntax has been removed.
So replace any occurance of [1..9]
with List.range 1 9
.
You are not allowed to have primes in variable names, so things like type'
are renamed to type_
.
Elm used to let you take normal functions and use them as infix operators. This is most notable in the case of andThen
which is pretty much the only function that used this feature. You will want to make the following updates to your code:
-- old
andThenIn17 : Result String Int
andThenIn17 =
String.toInt "1234"
`Result.andThen` \year -> isValidYear year
-- andThen : Result x a -> (a -> Result x b) -> Result x b
-- new
andThenIn18 : Result String Int
andThenIn18 =
String.toInt "1234"
|> Result.andThen (\year -> isValidYear year)
-- andThen : (a -> Result x b) -> Result x a -> Result x b
Notice that the backtick style is replaced by pipelining. The onError
function has been flipped in the same way, so if you are working with tasks you may say something like this in 0.18:
type Msg = NewText String | DidNotLoad
tasksIn18 : Task x Msg
tasksIn18 =
Http.toTask (Http.getString "http://example.com/war-and-peace")
|> Task.andThen (\fullText -> Task.succeed (NewText fullText))
|> Task.onError (\error -> Task.succeed DidNotLoad)
This also means that andThen
and onError
group together much better than in the infix style.
This change should be happening across the entire Elm ecosystem as package authors upgrade to 0.18.
A couple functions have been removed or renamed.
-
objectN
becomesmapN
(Note:object1
becomesmap
)tupleN
becomesmapN
withindex
(:=)
becomesfield
andThen
args flip
-
shiftLeft
becomesshiftLeftBy
and args flipshiftRight
becomesshiftRightBy
and args flipshiftRightLogical
becomesshiftRightZfBy
and args flip
-
andThen
args fliponError
args flip- Removed
perform : (x -> msg) -> (a -> msg) -> Task x a -> Cmd msg
- Added
perform : (a -> msg) -> Task Never a -> Cmd msg
- Added
attempt : (Result x a -> msg) -> Task x a -> Cmd msg
- Removed
toMaybe
andtoResult
in favor of usingonError
directly
-
- Renamed
formatError
tomapError
to match names inTask
andThen
args flip
- Renamed
-
andThen
args flip- Removed
oneOf
-
andThen
args flip
-
Basics.fst
becomesTuple.first
Basics.snd
becomesTuple.second
The following packages have changed a little bit:
-
elm-lang/html
collapsedHtml.App
intoHtml
. So you need to remove anyimport Html.App
imports and refer toHtml.program
instead. -
elm-lang/http
was redone to be easier and have more features. It now supports tracking progress and rate-limiting HTTP requests. It should be pretty easy to upgrade to the new stuff, but if you have a complexTask
that chains many requests, you will want to use theHttp.toTask
function to keep that code working the same. -
elm-lang/navigation
no longer has its own concept of aParser
. You just turn aNavigation.Location
into a message and it is fed into your normalupdate
function. This meansNavigation.program
is now much closer toHtml.program
so this should simplify things a bit. -
evancz/url-parser
is pretty much the same, but works better and is friendlier. New things include:- You can use
<?>
to parse query parameters. - Some bugs about parsing leading and trailing slashes are fixed.
- The parser backtracks, always finding a valid parse of the URL if one exists.
- You can use
parsePath
to parse aNavigation.Location
directly.
- You can use
In all cases, the packages have become simpler and easier to use. The actual changes did not seem to be too serious as I upgraded elm-lang.org
and package.elm-lang.org
and all the examples I control.