Skip to main content
Stack Overflow
  1. About
  2. For Teams
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Filter by
Sorted by
Tagged with
0 votes
1 answer
146 views

How do I make the "return" function from the Monad class return a phantom parameter?

MRE: module Temp where data Some r a = Thing r a instance Monad (Some r) where return :: a -> Some r a return a = Thing r a -- <- The is a phantom argument (somewhat like the s in ...
1 vote
1 answer
74 views

What does it mean that the arguments to <*> and their associated effects are known statically?

I'm reading the paper Selective Applicative Functors. So far I've read from page 16 out 29, and I think I've understood the gist of this abstraction, but I'm having some trouble with some basic ...
3 votes
2 answers
107 views

How to use Haskell `do` notation with multiple monad constraints

I'm still quite new to Haskell and don't have a great grasp of monads intuitively. I'm trying to write the function below: applyPandocFilters :: (MonadIO m, PandocMonad m) => Pandoc -> m Pandoc ...
0 votes
2 answers
187 views

How is Maybe a monad in Haskell?

A monad, I've been told, is a monoid of X in the category of endofunctors of X, where X is some category. Maybe is supposedly then a monoid, which means that it is: an object of a category, some ...
1 vote
1 answer
96 views

State Monad in Haskell . How to adapt functors, applicatives and monads to characteristics and Die Rolls

I'm trying to use State Monad in a personal section of code in order to have a more natural code . The problem and the code section are the following ones . I'm trying to ask interactively a user to ...
Yago's user avatar
  • 445
0 votes
1 answer
127 views

Which monad would be best suited to a structure where lifting any value with pure, return will always yield the identity element of the trivial group? [closed]

I need to meet the following requirements: 1)Trivial group: Only a single element exists, which serves as its own identity (e.g., for addition, 0; for multiplication, 1). 2)Lifting (return/pure): Any ...
1 vote
1 answer
109 views

How to implement interrupts in pure functional languages [closed]

How would a pure functional programming language with encapsulated effects via monads (e.g. haskell) deal with interrupts? Usually, interrupt handlers modify some global state, but accessing a global ...
3 votes
2 answers
188 views

Why doesn't MonadMaybe exist?

The way I look at MonadState, for instance, is that any type (or set of types, e.g. ReaderT r m a) that implements it, must support get+put (or alternatively just state) in order to behave like the ...
3 votes
3 answers
158 views

Is catching Exceptions Considered Code-smell in Haskell? [closed]

I recently found myself needing to list all the subdirectories in the directory specified by a certain pathname. There is getDirectoryContents in System.Directory. getDirectoryContents :: FilePath -&...
2 votes
1 answer
111 views

What kind of value do you get when you apply "return" to a value without a constraint?

If you apply return to 'a' you get a value of type m Char, belonging to the Monad class: :t return 'a' → return 'a' :: Monad m => m Char. If you apply the resulting value to some other value, say, ...
3 votes
2 answers
146 views

What is bound to the parameter "b" in the expression "b <- (+10)" in the do-expression?

Here is a piece of code from the book "Learn You a Haskell for Great Good!" by Miran Lipovača: addStuff :: Int -> Int addStuff = do a <- (*2) b <- (+10) return (a+b) What is ...
8 votes
4 answers
672 views

How to convert a std::optional to a std::expected?

I'm trying to convert a std::optional into a std::expected using a lambda function. The code I have written does not compile. The compiler complains that the monadic functions of std::optional must ...
0 votes
1 answer
179 views

How to serialize Free-monad based DSLs?

There is a previous question with no answer Serialize a program written in a free monad? Is there a canonical way to serialize Free-monad based DSLs? Or is the answer that create a second data type ...
4 votes
4 answers
163 views

Nested monadic operations produces unreadable code

I want help writing readable code for composing the monadic callbacks of c++23. What I'm finding is that, while the code I'm producing tends to be more correct, scenarios where I need to merge the ...
Thornsider3's user avatar
0 votes
1 answer
61 views

How to parametrize the type of a class instantiated through @classmethod in python

I'm trying to define a generic base class that can instantiate wrapped instances of itself like so from typing import Callable, TypeVar, Generic T = TypeVar("T") U = TypeVar("U") ...
Seb's user avatar
Seb
  • 21

15 30 50 per page
1
2 3 4 5
...
237

AltStyle によって変換されたページ (->オリジナル) /