Drkcore

07 12 2012 Haskell Tweet

Haskellのarrは何を持ち上げるのかがちょっと分かった気になった

Hakyllのサンプルを読んでいてarrowの使い方がわかりやすくていいなーと思ったんだがarrの必要性がよく分からなかった。

例えばtagblogの22行目のarrとか。

>>> arr (renderDateField "date" "%B %e, %Y" "Date unknown")

renderDateFieldは

renderDateField :: String  -- ^ Key in which the rendered date should be placed
                -> String  -- ^ Format to use on the date
                -> String  -- ^ Default value, in case the date cannot be parsed
                -> Page a  -- ^ Page on which this should be applied
                -> Page a  -- ^ Resulting page
renderDateField = renderDateFieldWith defaultTimeLocale

だからrenderDateField "date" "%B %e, %Y" "Date unknown"の型は

Page a -> Page a

でarrで持ち上げる必要ないんじゃないかなぁと。

と思ったので、22行目のarrを除いてコンパイルしてみた。

$ ghc --make test.hs 
[1 of 1] Compiling Main             ( test.hs, test.o )

test.hs:22:17:
    Couldn't match expected type `Compiler (Page String) b0'
                with actual type `Page a0 -> Page a0'
    In the return type of a call of `renderDateField'

あれ?arrってCompiler型に持ち上げていたのか。ということはCompiler型ってAllowなのか

みてみると、

data Compiler a b = Compiler
    { compilerDependencies :: Reader DependencyEnvironment Dependencies
    , compilerJob          :: a -> CompilerM b
    }

あーなるほど。こういうのもArrowになるのか。

というわけで、arrの使い道がちょっと分かった(気がした)。

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021