Skip to main content
Best practices
0 votes
1 replies
107 views

I currently have this implementation: data RoseTree a = RoseTree a [RoseTree a] preorder :: Tree a -> [a] preorder (Tree x ts) = x : concatMap preorder ts instance Foldable Tree where foldr :: (...
Panic's user avatar
  • 93
Best practices
2 votes
6 replies
117 views

Is there a convenient way to short circuit a Seq.fold evaluation? For example, the following function evaluates if parenthesis are balanced in a string. let isBalanced str = (([], str) ||> Seq....
gileCAD's user avatar
  • 2,633
0 votes
1 answer
83 views

So this is the data definition and my function. Task 3 Define addAll, which adds a list of expressions together into a single expression without introducing any 'junk'. You could use foldr since it ...
charlotte chang's user avatar
2 votes
1 answer
150 views

This is from a guide of exercises that focuses on structural recursion (foldr), primitive recursion (recr) and iterative recursion (foldl) in Haskell. The suggestion for this excercise is to return a ...
Santiago Roussineau's user avatar
0 votes
2 answers
92 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
1 vote
2 answers
109 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
0 votes
2 answers
250 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
  • 762
4 votes
3 answers
160 views

I have written a C++20 concept myrequirement: template<typename T> concept myrequirement= requires(T s) { { s.type() } -> std::same_as<uint8_t>; }; enum MyType { TYPE1, ...
grybouilli's user avatar
2 votes
1 answer
98 views

I have a collection of struts, each with a data_t member type (other members omitted): struct A { using data_t = int; }; struct B { using data_t = double; }; struct C { using data_t = bool; }; // etc. ...
Dominic Kerr's user avatar
8 votes
4 answers
420 views

Suppose we have data Nat = Z | S Nat type Vec :: Nat -> Type -> Type data Vec n a where Nil :: Vec Z a (:::) :: Vec n a -> Vec (S n) a infixr 4 ::: deriving instance Foldable (Vec n) ...
dfeuer's user avatar
  • 48.8k
3 votes
2 answers
121 views

For learning purposes I've emulated List.foldBack. The emulated version is head-recursive. Is there an elegant way to convert it to the tail-recursive version? let li : int list = [1;2;3] let rec ...
Alexander K.'s user avatar
0 votes
0 answers
41 views

I would like to fold all JS doc comments within my code. I just found that folding all comments can be done with Ctrl+K Ctrl+/. Yet I am still wondering if there is a way to fold all occurrences in ...
SP4CEBAR's user avatar
6 votes
2 answers
151 views

The following problem and partial solution are from Richard Bird's Thinking Functionally with Haskell (pp 132-133, 139) given foldl f e (x:xs) = foldl f (f e x) xs foldl f e [] = e Prove foldl (@) e ...
planarian's user avatar
  • 2,183
0 votes
1 answer
104 views

Recently when I self-learnt MIT 6.5151 course, I first read CS 61AS Unit 0 as the preparation. Then I have read SICP 1 to 2.1 (with related lecture notes) as ps0 requires (also read 2.2.1 as CS 61A ...
An5Drama's user avatar
  • 762
-1 votes
1 answer
195 views

I use vscode. Foldable code blocks used to have fold/unfold arrows in the ruler, now however, we have the sticky scroll. Is there a way to re-enable the fold arrows in the ruler?
Walkerbo's user avatar
  • 663

15 30 50 per page
1
2 3 4 5
79