This blog runs on a barebones blogging framework that I knocked together using Yesod 1.1 back in 2013. I recently ported it over to Yesod 1.4. Apart from the few changes that I have detailed below, everything worked straight away. Refactoring code in Haskell is a very different experience compared to fully dynamic languages.
Here are some notes on the changes that I encountered between Yesod 1.1 and 1.4. Perhaps these will be useful for someone.
Previously I used aformM to get the current time in a form:
Now, use lift (liftIO getCurrentTime):
Some new names clash with the Prelude, e.g. maximum is not the usual function from the Prelude, but rather something from Data.MinLen that encodes type-level natural numbers.
*Main> :t maximum maximum :: MonoFoldableOrd mono => MinLen (Succ nat) mono -> Element mono *Main> :t P.maximum P.maximum :: Ord a => [a] -> a
No unKey or PersistInt64
Persistent values in the old system looked like this:
and we could use PersistInt64 to construct the value, or unKey to deconstruct it.
*Main> :t PersistInt64 PersistInt64 :: GHC.Int.Int64 -> PersistValue *Main> :t unKey unKey :: KeyBackend backend entity -> PersistValue
Now values look like:
Old code like
We could also use toPathPiece:
*Main> :t toPathPiece :: Key Entry -> Text toPathPiece :: Key Entry -> Text :: Key Entry -> Text
If you’re wondering how to find such a thing, look at the output of :info Key in ghci which
includes these lines:
I believe that the more general option is fromSqlKey:
This should work over any SQL backend, unlike the
older code that was tied to the particular implementation (e.g. 64bit
Similarly, old code constructed a Key from an integer:
New code uses toSqlKey since the PersistInt64 constructor isn’t available:
Original blog framework, written with Yesod 18.104.22.168: https://github.com/carlohamalainen/cli-yesod-blog.
New blog framework, compiles against Yesod 1.4: https://github.com/carlohamalainen/cli-yesod-blog-1.4.