monoids

    3熱度

    1回答

    我正在製作用於組合Retry Execution策略的Monoid,而RetryExecutor [T]是基礎類型。我已經定義了以下基本類型和幺: trait RetryExecutor[C] { def retry[T](f: C => T)(context: C): T def predicate: Option[Throwable] def applicati

    2熱度

    1回答

    我遇到了一些問題HXT:我試圖找到符合某些條件的文檔中的所有節點,並且我試圖將鏡頭/ XPaths作爲謂詞使用Control.Arrow.<+>,如this guide所示。但是,當我嘗試「運行」文檔上的箭頭時,我得到重複的結果。有沒有簡單的方法來刪除重複項,或以更有意義的方式組合測試?這是我的代碼: run :: App -> IO() run a = do inputContent

    18熱度

    4回答

    我在閱讀學習你一個哈斯克爾,我已經介紹了應用程序,現在我在monoids。我對這兩種理解都沒有問題,儘管我發現應用在實踐中很有用,monoid也不是那麼完美。所以我想我對Haskell不瞭解。 首先,談到Applicative,它創建了一些類似於統一語法的操作來對「容器」執行各種操作。所以我們可以用正常功能對Maybe,列表執行操作,IO(?我應該說的單子我不知道單子還),功能: λ> :m +

    7熱度

    4回答

    我需要做出一個可摺疊實例玫瑰樹數據結構: 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

    10熱度

    3回答

    我想要做的是瑣碎的手工定義,基本上 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

    3熱度

    1回答

    我試圖使用HSpec和QuickCheck來驗證屬性的猿(關聯性和標識元素)。我要驗證特定的實例,但想保留大部分代碼多態。這是我想出了幾個小時後: module Test where import Test.Hspec import Test.QuickCheck import Data.Monoid instance (Arbitrary a) => Arbitrary (Sum a

    4熱度

    1回答

    考慮下面的僞代碼冒泡排序 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] >

    0熱度

    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)

    5熱度

    1回答

    對不起,可怕的標題。我正在嘗試爲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 `

    0熱度

    1回答

    這是我的代碼。它允許創建使用卡斯巴 trait TypesafeQuery[ObjectType, BuildType] { def build: BuildType } trait TypesafeMongoQuery[ObjectType] extends TypesafeQuery[ObjectType, DBObject] case class TypesafeMo