19,243 questions
0
votes
1
answer
111
views
Obtaining mutable arrays from immutable
Is it possible to obtain an array with O(1) read and write access (like Haskell's STArray) using a read only array (such as Haskell's Data.Array.Array)?
Or is there a wrapper around pure functions ...
1
vote
1
answer
47
views
Is this error due to a limitation of Idris' compiler/type checker or is it a language necessity?
You can put together the following code by collecting some snippets from Type-Driven Development with Idris's Chapter 8:
data Vect : Nat -> Type -> Type where
Nil : Vect Z a
(::) : a -> ...
Best practices
0
votes
1
replies
100
views
Rust: Iterator<(key, value)> to HashMap<Key, Vec<Value>> the functional way
I have a vector of key-value pairs, where keys can be duplicate, or rather, I have an iterator that I eventually collect to that vector. I need to get a HashMap with those keys, but vectors of values ...
Best practices
3
votes
4
replies
135
views
Functional pattern, good or bad?
When writing modules, i am always struggling trying to identify the related dependencies of the functions, properties, etc...
That's why i am now trying to code using only pure functions, and to ...
0
votes
1
answer
140
views
How can I implement consistent typed error propagation in C# without scattering try/catch across layers?
I have a C# application with multiple layers (controllers, services, domain logic, and background workers). Error handling has become inconsistent because many methods contain their own try/catch ...
0
votes
0
answers
59
views
Mutually recursive stack-safe functions with different types
I want to make my mutually recursive functions stack-safe, but because they have different signatures - one traverses a list and other a tree(?) of sorts - I'm not clear how to go about this.
Here's ...
1
vote
2
answers
167
views
Replacing the element in the list with the specific index using `foldr` —— Exercise 1.19 of Essentials of Programming Language
Here is the question from Mitchell Wand's Essentials of Programming Language:
Exercise 1.19 [⋆ ⋆] (list-set lst n x) returns a list like lst, except that the n-th element, using zero-based indexing, ...
Advice
0
votes
2
replies
139
views
How to effectively use ASP.NET core Hybrid Cache with Result<T> type
Suppose a scenario where:
you need to execute an expensive operation which can fail or succeed.
the result of the operation is modeled by using a result object Result<T>. The result object ...
Best practices
5
votes
3
replies
156
views
Is there a way to tuck in Ord inside Applicative?
I had a nice idea of using applicative for nondeterministic financial modelling. Or maybe it is a simple case of sentization. So the basic example is to define newtype ValueRange.
newtype ValueRange a ...
0
votes
1
answer
98
views
How to split a shell command into tokens in a quote-aware fashion? [closed]
The task
Given the following string¹
one ' two 'three four
the required function should split it in 3 tokens (one, two three, and four), in agreement with how the bash shell does:
$ function ...
0
votes
1
answer
137
views
What's the idiomatic/correct way to split a string into its first word and the rest of the string? [closed]
tl;dr
Ideally, I'd want the following
"hello world" is split in "hello" and " world"
" world" is split in "" and " world"
"hello "...
4
votes
1
answer
125
views
Understanding usage of withFileBlocking with named pipes
The following program
assumes that /path/to/mypipe is a named pipe, e.g. created via mkfifo /path/to/mypipe, with no readers/writers waiting yet,
runs two threads, of which
the main thread keeps ...
3
votes
2
answers
200
views
Functional core - Imperative shell: dealing with logic dependant on conditional & expensive IO operations
tldr; how does one deal with logic that depends on data that are too heavy to fetch up-front when subscribing to the functional core, imperative shell line of thought?
Years ago I was inspired by Gary ...
3
votes
2
answers
111
views
Why doesn't readFile block on unix pipe in which no write has happened yet?
If in a terminal I enter
mkfifo /tmp/pipe
echo hello > /tmp/pipe
(which blocks) and in another I run the haskell program
main = readFile "/tmp/foobar" >>= putStr
then I see it ...
2
votes
1
answer
90
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 ...