applicative

    4熱度

    3回答

    我想實現應用型實例這樣的類型: newtype State s a = State {runState :: s -> (a, s)} 我有(< *>)功能有些不同的想法。實現它 的一種方式。這使我的心是 (<*>) :: State s (a -> b) -> State s a -> State s b State f <*> State s = State $ do (fa,

    1熱度

    1回答

    嗨,我有以下Scala代碼與cats庫 results = patrons.map(p => { (verifyCardId(p.cardId), verifyAddress(p.address)).map2( (maybeValidCard, maybeValidAddress) => { val result = for { idCheck <- may

    1熱度

    1回答

    在Haskell我們可以寫這樣的代碼: 如何做同樣的事情在F#? 我試着寫代碼這樣的事情,但它不是同一 let (<*>) f v = match v with | Some v' -> match f with | Some f' -> Some (f' v') | _ -> None | _ -> None let cnst

    0熱度

    1回答

    這是一個後續行動,我以前question: 假設我想用Applicative應用功能A => B => C到List[A]和List[B]。 我相信它看起來像在Haskell: pure f <*> as <*> bs // apply f to List[A] and List[B] 或 f <$> as <*> bs 是否cats提供這樣的語法?你如何用cats來寫?

    11熱度

    6回答

    我讀格雷厄姆·赫頓在Haskell書編程和我有一些問題了解<*>和部分應用程序如何被用來解析字符串。 我知道pure (+1) <*> Just 2 產生Just 3 因爲pure (+1)產生Just (+1),然後Just (+1) <*> Just 2 產生Just (2+1)然後Just 3 但在更復雜的情況是這樣的: -- Define a new type containing a p

    -1熱度

    1回答

    我想在java中編寫一些函子,monads和applicatives。我找到了一些,並選擇了下面的一個。 在術語類別理論中,什麼是get()返回? 單位()似乎是某種身份,但從什麼到什麼?或者也許這是一個構造函數? 我看到了one有一個get()函子的定義。這將返回什麼? abstract class Functor6<F,T> { protected abstract <U> Func

    2熱度

    1回答

    我試圖安裝一個應用程序Termite - Util但我在與線得到這個錯誤14 newtype CE m a = CE {unCE :: m a} deriving (Monad) 錯誤說: ContextError.hs:14:45 : 沒有適用於(適用(CE m)) 由數據類型聲明的「派生」子句產生 可能的修正: 使用獨立的「派生實例」聲明 因此您可以sp ecify自己的實例上下文 當導出

    2熱度

    1回答

    我擡頭實施,它更神祕: -- | Sequence actions, discarding the value of the first argument. (*>) :: f a -> f b -> f b a1 *> a2 = (id <$ a1) <*> a2 -- This is essentially the same as liftA2 (flip const), but if

    4熱度

    1回答

    我想能夠使用scalaz的| @ |在我自己的應用函數上。 例子: val spread: Source[Yield] = (y2 |@| y1)(_ - _) 這是我的課 sealed abstract class Source[+A] { def map[B](f: A => B): Source[B] def unit[A](a: A): Source[A] d

    2熱度

    3回答

    我想學習如何在JavaScript中使用應用函子,並遇到了ap方法。我想用它來三個陣列相結合,像這樣: const products = ['teeshirt', 'sweater'] const options = ['large', 'medium', 'small'] const colors = ['red', 'black'] 所以按照該documentation我嘗試了這一點: