我遇到了一些問題HXT:我試圖找到符合某些條件的文檔中的所有節點,並且我試圖將鏡頭/ XPaths作爲謂詞使用Control.Arrow.<+>,如this guide所示。但是,當我嘗試「運行」文檔上的箭頭時,我得到重複的結果。有沒有簡單的方法來刪除重複項,或以更有意義的方式組合測試?這是我的代碼: run :: App -> IO()
run a = do
inputContent
我需要做出一個可摺疊實例玫瑰樹數據結構: data Rose a = a :> [Rose a]
deriving (Eq, Show)
用下面的獨異與玫瑰有關的類/實例: instance Functor Rose where
fmap f (a :> bs) = (f a) :> (map (fmap f) bs)
class Monoid a where
我想要做的是瑣碎的手工定義,基本上 maybeCombine :: (a->a->a) -> Maybe a -> Maybe a -> Maybe a
maybeCombine _ Nothing Nothing = Nothing
maybeCombine _ (Just a) Nothing = Just a
maybeCombine _ Nothing (Just a) = Just
我試圖使用HSpec和QuickCheck來驗證屬性的猿(關聯性和標識元素)。我要驗證特定的實例,但想保留大部分代碼多態。這是我想出了幾個小時後: module Test where
import Test.Hspec
import Test.QuickCheck
import Data.Monoid
instance (Arbitrary a) => Arbitrary (Sum a
考慮下面的僞代碼冒泡排序 procedure bubbleSort(A : list of sortable items)
repeat
swapped = false
for i = 1 to length(A) - 1 inclusive do:
/* if this pair is out of order */
if A[i-1] >
我的樹 data Tree a = Leaf a
| Node [Tree a]
deriving (Show)
以下定義和可摺疊以下實例: instance Foldable (Tree) where
foldMap f (Leaf t) = (f t)
foldMap f (Node t) = (foldMap `mappend` (foldMap f) t)
對不起,可怕的標題。我正在嘗試爲Monad包裝一個類型爲Monoid的Applicative實例。 instance (Monad m, Monoid o) => Applicative (m o) where
pure x = return mempty
xm <*> ym = do
x <- xm
y <- ym
return $ x `