Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
44 views

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 ...
joel's user avatar
  • 8,122
1 vote
2 answers
113 views

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, ...
YCH817's user avatar
  • 123
Advice
0 votes
1 replies
78 views

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 ...
Enrico Massone's user avatar
Best practices
5 votes
3 replies
149 views

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 ...
Dominik G's user avatar
  • 614
0 votes
1 answer
91 views

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 ...
Enlico's user avatar
  • 30.3k
0 votes
1 answer
124 views

tl;dr Ideally, I'd want the following "hello world" is split in "hello" and " world" " world" is split in "" and " world" "hello "...
Enlico's user avatar
  • 30.3k
4 votes
1 answer
115 views

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 ...
Enlico's user avatar
  • 30.3k
3 votes
2 answers
151 views

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 ...
oligofren's user avatar
  • 23.4k
3 votes
2 answers
104 views

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 ...
Enlico's user avatar
  • 30.3k
2 votes
1 answer
86 views

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 ...
Enlico's user avatar
  • 30.3k
1 vote
2 answers
237 views

I’m working with large nested associative arrays in PHP and I need to apply transformations (like map, filter, reshape) immutably, meaning the original array should not be modified. The problem is ...
Dharm's user avatar
  • 21
1 vote
0 answers
120 views

Consider the following toy code which performs very simple (a few instructions) operations on a hot loop over a large amount of values: template<float (*f)(float)> void process_f(int count, ...
F.X.'s user avatar
  • 7,515
0 votes
1 answer
59 views

I am having trouble getting the following code to work. I got it to work originally, then I changed it so all the Nonterminals also have positions. And I added the method parseLexeme that transforms ...
Jacob Bauer's user avatar
1 vote
1 answer
108 views

I've created a small library called StreamX, which acts like a type-safe, index-aware zipper to enable parallel streaming over multiple lists. It supports functional operations like forEach, map, ...
M S's user avatar
  • 19
7 votes
2 answers
206 views

In Haskell in Depth, Chapter 11, there's an example aimed at avoiding character escaping in GHCi, which is what happens automatically when you enter print "ë", as it'll be printed like "...
Enlico's user avatar
  • 30.3k
0 votes
1 answer
124 views

I start with several containers of things: [1,2,3] fromList [4, 42, 77] Array Vertex [99, 44, 33] -- The specific containers are just examples. It would be nice to not assume -- they are Ord instances,...
James Strieter's user avatar
0 votes
1 answer
85 views

I am a beginner to functional programming where most of my experience comes from Java/Kotlin. From my understanding functional programming has special names for certain function signatures. Type ->...
liampace's user avatar
0 votes
2 answers
84 views

Suppose you had a programming language in which all variables are immutable. Modifying iterables could be accomplished by providing a magic variable that is immutable during an iteration step, but ...
Armin Repsold's user avatar
0 votes
2 answers
80 views

I have a map which lays down prices of commodities in different currencies val commpricemap: Map[String , Map[String, Double]] = ??? AN example of an entry for gold is as below: ("AU" -> ...
IUnknown's user avatar
  • 9,987
1 vote
1 answer
111 views

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 ...
Alec You's user avatar
4 votes
1 answer
98 views

For Vec2, Vec3, and others from Data.Vector.Fixed.Boxed, I see a Functor instance, so something like this type-checks: fff :: B.Vec2 Int -> B.Vec2 Int fff = fmap (+1) and fmap is just Data.Vector....
Enlico's user avatar
  • 30.3k
0 votes
0 answers
55 views

I am in the process of trying to implement Reflection Without Remorse in Typescript, as an exercise, and in the process I'm implementing a bit of a standard library for functional programming. For ...
JSONMagic's user avatar
0 votes
0 answers
56 views

Suppose I were trying to build lazy datastructures in a lazy language (Im currently using Typescript, but the specific language matters little). The obvious implementation is class Lazy<T> { ...
JSONMagic's user avatar
-1 votes
3 answers
116 views

What package should I go to if I want to have fixed-size array like C++'s std::array? I've seen at least two packages exist: vector-sized fixed-vector I've started playing a bit with the latter, but ...
Enlico's user avatar
  • 30.3k
0 votes
3 answers
99 views

I have two files in a library I am creating: file1.py def func1(a, b): c = a + b return c file2.py def func2(a, b): c = a - b return c Now I want each file to have a function that ...
Alex's user avatar
  • 13
1 vote
2 answers
104 views

I'm working out of Scala for the Impatient (3rd Edition). (I'm not doing this for a class.). I'm trying to implement a factorial function using to and reduceLeft without a loop or recursion. This ...
Christopher Spears's user avatar
1 vote
3 answers
120 views

I implemented a following algorithm: val acceptedTopics: Set[String] = ... val arr: List[JValue] = ... // JValue is an algebraic trait extended by JString, JInt, and other types. val topics = arr....
Trismegistos's user avatar
  • 3,903
1 vote
2 answers
93 views

I have a Option sequence of dates - from which I need to SAFELY extract the first date after a given date( or else return the given date). The below seems to be a lot of code for such a simple used ...
IUnknown's user avatar
  • 9,987
2 votes
1 answer
54 views

I am trying to write a simple tuple type open import Agda.Builtin.List mutual f : List Set -> Set f T = g T T where g : List Set -> List Set -> Set g [] T = Tuple T g (t ∷ ...
HPSmash77's user avatar
0 votes
1 answer
113 views

I was fascinated by this video on visualization of Haskell heap, but unfortunately I haven't been able to use ghc-vis. My understanding is that it is too old now. (Feel free to suggest how to actually ...
Enlico's user avatar
  • 30.3k
0 votes
2 answers
249 views

Recently to better understand the advantages and disadvantages of lazy evaluation, I check for some details of Haskell. I did that to do exercise 5.9 in SDF (Software Design for Flexibility) More ...
An5Drama's user avatar
  • 774
0 votes
1 answer
53 views

So I'm doing a bit of tweaking with elm to become familiar with it, but when trying to make functions for handling the different views of the application, there's a rounte that doesn't work and I can'...
m00nsh1n3's user avatar
0 votes
0 answers
63 views

I'm attempting to solve the DMOJ problem Tree Tasks(https://dmoj.ca/problem/treepractice1), which involves computing the diameter and radius of a weighted tree. My goal is to implement a solution in ...
AlanHacker's user avatar
3 votes
2 answers
191 views

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 ...
Enlico's user avatar
  • 30.3k
0 votes
3 answers
117 views

In the Examples section of foldr's documentation, I read that Infinite structures ⚠️ Applying foldr to infinite structures usually doesn't terminate. It may still terminate under one of the following ...
Enlico's user avatar
  • 30.3k
2 votes
1 answer
59 views

I'm reading Associated Types with Class, and I'm running into code that doesn't seem to be compilable. Is it just a typo in the paper, or is that things have changed a lot since 2004, when the paper ...
Enlico's user avatar
  • 30.3k
6 votes
1 answer
64 views

If I do λ> :k Monad at the ghci prompt, I get Monad :: (* -> *) -> Constraint Out of curiosity, is there a way to have it print Type instead of *? I am reading Thinking with Types, and I've ...
Enlico's user avatar
  • 30.3k
0 votes
0 answers
103 views

In systems that support higher-rank polymorphism (such as Peyton Jones et al.'s "Practical Type Inference for Arbitrary-Rank Types"), I’m trying to understand how to reason about specificity ...
NisNis's user avatar
  • 135
-1 votes
2 answers
77 views

In simple words: If A and B are equivalent multisets, then elements not in A are not in B as well. lemma ElementExclusionLemma<T>(seqa: seq<T>, seqb: seq<T>, x: T) ensures multiset(...
f1sherb0y's user avatar
1 vote
2 answers
51 views

I'm working with Dafny and trying to understand how specifications, particularly modifies and ensures multiset, affect verification. I have a method do_nothing which is specified to modify an array a ...
f1sherb0y's user avatar
2 votes
1 answer
126 views

I want to make a simple function in R that works with data.frames/tibbles or with a data.table. So I created a new method: pesquisarComposicao <- function(BASE, ...) { UseMethod("...
droubi's user avatar
  • 125
1 vote
3 answers
181 views

For instance consider this function, that could be used in a WM to allow moving a window from one desktop to another on a given display, moveWindowSTM :: Display -> Window -> Desktop -> ...
Enlico's user avatar
  • 30.3k
3 votes
1 answer
86 views

How do let and case differ in terms of lazyness? Where do I find the information myself? And how do I experiment with it in ghci? Some context This incomplete piece of code is an excerpt from Parallel ...
Enlico's user avatar
  • 30.3k
0 votes
2 answers
60 views

I have this code where I've updated an object in React. When you click "Most upvoted", it takes an object, sorts it by votes, and then updates the state with it. The problem is, it won't ...
CodeNinja's user avatar
2 votes
1 answer
80 views

In Parallel and Concurrent Programming in Haskell by Simon Marlow, chapter 7 starts at page 125 with this example, import Control.Concurrent import Control.Monad import System.IO main :: IO () main = ...
Enlico's user avatar
  • 30.3k
1 vote
2 answers
82 views

In Parallel and Concurrent Programming in Haskell by Simon Marlow, at pages 133 and 134 the following code is shown: type Name = String type PhoneNumber = String type PhoneBook = Map Name ...
Enlico's user avatar
  • 30.3k
2 votes
1 answer
106 views

In Parallel and Concurrent Programming in Haskell by Simon Marlow, the implementation of bracket is shown, bracket :: IO a -- ^ computation to run first (\"acquire resource\")...
Enlico's user avatar
  • 30.3k
3 votes
3 answers
118 views

I'm reading Parallel and Concurrent Programming in Haskell by Simon Marlow, and I initially read this suggestion fairly lightly, It is always better to use throwIO rather than throw in the IO monad ...
Enlico's user avatar
  • 30.3k
2 votes
1 answer
178 views

I am quite comfortable with Agda. I decided to experiment with Lean, but I find that propositional equality is really messing with me. Sometimes I find that rfl just works, but at other times it doesn'...
Joris KBos's user avatar
2 votes
0 answers
144 views

Say I have some simple struct, eg: struct SomeStruct { things: Vec<usize> recent_thing: Option<usize> } I'm trying to assert some invariant on this struct. For example, maybe we want ...
ijustlovemath's user avatar

1
2 3 4 5
385