comonad Questions

1

Recall the Applicative class: class Functor f => Applicative f where pure :: a -> f a liftA2 :: (a -> b -> c) -> f a -> f b -> f c (<*>) :: f (a -> b) -> f a -&g...
Rybinsk asked 26/8, 2023 at 6:28

1

Solved

Edward Kmett writes on his blog that using the Co newtype (from the kan-extensions package), it's possible to derive a Monad from any Comonad. I'd like to learn how to mechanically do this for any ...
Irriguous asked 2/4, 2023 at 10:36

1

In Haskell, Given a monad m, there is mfix :: (a -> m a) -> m a that computes the fixed-point of a monadic computation. Dually, given a comonad w, there is cofix :: w (w a -> a) -> a th...
Crist asked 15/3, 2023 at 12:35

1

Solved

I'm trying to get more proficient with recursion schemes as they have so far been really helpful for turning gnarly explicit recursion code into something less spike-y. One of the other tools I ten...

2

Solved

On Twitter, Chris Penner suggested an interesting comonad instance for "maps augmented with a default value". The relevant type constructor and instance are transcribed here (with cosmeti...
Yorker asked 21/9, 2020 at 1:49

1

Solved

As State monad can be factorized into Product (Left - Functor) and Reader (Right - Representable). Is there a way to factorize Continuation Monad? Below code is my attempt, which wont type check...
Hollah asked 17/4, 2020 at 9:5

2

Solved

Can we solve this equation for X ? Applicative is to monad what X is to comonad
Verecund asked 17/1, 2016 at 10:8

1

Solved

Given the following from fp-course: class Functor f where (<$>) :: (a -> b) -> f a -> f b class Functor f => Extend f where (<<=) :: (f a -> b) -> f a -> ...
Seabury asked 23/1, 2019 at 3:17

3

Solved

What is Comonad, if it's possible describe in Scala syntax. I found scalaz library implementation, but it's not clear where it can be useful.
Henig asked 19/6, 2012 at 20:58

8

Solved

Is there a built-in function with signature :: (Monad m) => m a -> a ? Hoogle tells that there is no such function. Can you explain why?
Leia asked 19/12, 2011 at 21:22

1

Solved

This is a follow-up to the answer to my previous question. Suppose I need to map each item a:A of List[A] to b:B with function def f(a:A, leftNeighbors:List[A]): B and generate List[B]. Obviously...
Counterpoise asked 3/6, 2014 at 10:55

2

Solved

I've got a puzzle for you, I managed to write some code that would do these things using recursion-schemes, but it's incredibly messy and that usually means that I missed a useful abstraction some...
Suntan asked 19/3, 2017 at 19:22

1

Solved

I am using the Writer monad to keep track of an error ("collision") flag on arbitrary values (such as Int). Once the flag is set it is "sticky" and attaches itself to all values produced as a resul...
Testimony asked 7/3, 2017 at 23:32

1

Okay, so let's say you have the type newtype Dual f a = Dual {dual :: forall r. f(a -> r)->r} As it turns out, when f is a Comonad, Dual f is a Monad (fun exercise). Does it work the other...
Husbandry asked 16/12, 2015 at 1:39

1

The Cofree comonad is useful for iterating partial functions in a way that's polymorphic on the error type. Its coiter resembles forM-looping in an error monad, but it gathers the produced values i...
Cut asked 22/12, 2016 at 12:3

1

While musing what more useful standard class to suggest to this one class Coordinate c where createCoordinate :: x -> y -> c x y getFirst :: c x y -> x getSecond :: c x y -> y addC...
Humfrid asked 27/11, 2016 at 23:26

1

Solved

I've been playing with Cofree, and can't quite grok it. For example, I want to play with Cofree [] Num in ghci and can't quite get any interesting examples. For example, if I construct a Cofree t...
Godson asked 7/8, 2016 at 17:59

1

Solved

I have this simple Expr AST and I can easily convert it to String. import Prelude hiding (Foldable) import qualified Prelude import Data.Foldable as F import Data.Functor.Foldable import Data.Mono...

3

Solved

{-# LANGUAGE DeriveFoldable #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DeriveTraversable #-} import Control.Comonad import Data.Functor.Reverse import Data.List (unfoldr) First some co...
Caduceus asked 6/3, 2016 at 13:29

2

We can describe monad, as the computational context, and monad implementation exactly preserves the meaning of that context. For example Option - the context meaning is that the value might exist. ...
Aerator asked 4/3, 2016 at 9:30

2

Solved

What is the Comonad typeclass in Haskell? As in Comonad from Control.Comonad in the comonad package (explanations of any other packages that provide a Comonad typeclass are also welcome). I've vagu...
Amoeba asked 8/12, 2011 at 9:8

1

In this answer to "Can a monad be a comonad?" we see that Every Cofree Comonad over an Alternative functor yields a Monad. What would be the dual to this? Is there a class of functors that aut...
Exemplar asked 31/8, 2015 at 18:58

1

Solved

data Tree t = Empty | Node t (Tree t) (Tree t) We can create Functor instance and use fmap :: (t -> a) -> Tree t -> Tree a But what if instead of (t -> a) I want (Tree t -> a) so I co...
Indreetloire asked 30/8, 2015 at 10:10

1

Solved

Why when you define the function duplicate duplicate :: w a -> w (w a) for the Comonad typeclass (link) you have to modify all the elements "in the context" (i.e. change elements other tha...
Symptomatology asked 3/12, 2014 at 20:24

1

In my application, I'm trying to implement an animation system. In this system, animations are represented as a cyclic list of frames: data CyclicList a = CL a [a] We can (inefficiently) advance...
Alvy asked 4/9, 2014 at 23:34

© 2022 - 2025 — McMap. All rights reserved.