我剛剛開始接觸Haskell的動力,並熱愛我每天遇到的抽象概念,如lens。 我到一個地步,一個REST API鏡頭會一起工作是有用的,但我花幾個小時前,發現這是不可能的......是什麼呢? 我看到的主要問題是,我不是直接訪問的數據結構,但輸出其請求字符串(我的鏡頭語法也許是錯誤的): λ> over (user "robertplant") . set favoritesong
POST
考慮如下: class Test m a where
t :: Int -> m a
instance Test [] Int where
t i = [i]
instance Test Maybe Int where
t i | i == 0 = Nothing
| otherwise = Just i
main = do
prin
我想用Monad變形金剛嵌套作家monad兩次。這裏是一個草圖: import Control.Monad.Identity
import Control.Monad.Writer
data Struct = S Bool
instance Monoid Struct where
mempty = S True
mappend (S a) (S b) = S (a &
考慮以下功能: foo =
[1,2,3] >>=
return . (*2) . (+1)
爲了更好的可讀性和邏輯,我想(*2)和(+1)移動我的純函數的返回的左側。我可以這樣實現這一點: infixr 9 <.
(<.) :: (a -> b) -> (b -> c) -> (a -> c)
(<.) f g = g . f
bar =
[1,2,3]
我預計今年以評估3,但得到了一個錯誤,而不是: Idris> :let x = Just 2
Idris> 1 + !x
(input):1:3-4:When checking an application of function Prelude.Interfaces.+:
Type mismatch between
Integer (Type of (_bindA