1

我正在使用Web.Routes.Boomerang包构建站点地图,并且我想使用Data.Time.Calendar其中的日期:

data Sitemap = Index
         | Yearly Integer
         | Monthly Integer Int
         | Daily Day

sitemap = mconcat
    [ rIndex
    , rYearly . integer
    , rMonthly . integer </> int
    , rDaily . integer </> int </> int  -- does not typecheck
    ]

这不会进行类型检查,因为 for 的类型rDaily

rDaily :: Boomerang e tok (Day :- r) (Sitemap :- r)

并不是

rDaily :: Boomerang e tok (Integer :- (Int :- (Int :- r))) (Sitemap :- r)

我想从 转换(Integer :- (Int :- (Int :- r)))(Day :- r)。看起来xpure可以帮助我:

dayr :: Boomerang TextsError [Text] r (Day :- r)
dayr = xpure mkDay parseDay . (integer </> int </> int)
    where mkDay (y :- m :- d :- x) = fromGregorian y m d :- x
          parseDay (day :- x) = let (y, m, d) = toGregorian day in Just $ y :- m :- d :- x

sitemap = mconcat 
    [ rIndex
    , rYearly . integer
    , rMonthly . integer </> int
    , rDaily . dayr
    ]

但是,fromGregorian从上面看并不完整,我想使用fromGregorianValid

fromGregorian :: Integer -> Int -> Int -> Day
fromGregorianValid :: Integer -> Int -> Int -> Maybe Day
toGregorian :: Day -> (Integer, Int, Int) -- for completeness

如何翻转dayr以制作2014/95/13无效 URL 之类的东西?

4

0 回答 0