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我尝试了这一点: