Skip to main content

All Questions

3 votes
3 answers
93 views

Haskell basic - pattern matching vs list tail

I'm doing Set7.hs from haskell.mooc.fi/ Exercises7 -- Ex 5: reverse a NonEmpty list. -- -- PS. The Data.List.NonEmpty type has been imported for you -- below doesn't work -- reverseNonEmpty :: ...
bastiat's user avatar
  • 2,071
1 vote
2 answers
105 views

Implement a cake baking state machine in Haskell

Once again, I cannot wrap my head around this piece of cake: data Event = AddEggs | AddFlour | AddSugar | Mix | Bake deriving (Eq, Show) The cake baking states are as of now: data State = Start | ...
coderodde's user avatar
  • 997
3 votes
2 answers
231 views

how to converting function to cps recursively

i'd like to define cpsRec as follows but i couldn't. please let me know if you come up with ideas for implementation. import Control.Monad.Trans.Cont (Cont) type family ContRec r x where ContRec r (...
Mr. T's user avatar
  • 53
0 votes
2 answers
161 views

Why does matching this function parameter seprately work, but not with guards. (Haskell)

So, I have been trying to use SDL to make a simple GUI. This is so that I start to understand how to use haskell. In this case, I was using https://github.com/palf/haskell-sdl2-examples/blob/master/...
Naitik Mundra's user avatar
0 votes
2 answers
138 views

Pattern Matching Element in List in Haskell

Let's say I have the following type, where KType is defined somewhere else: data PExpr = PVal KType | PCall String [PExpr] I have a function: tryReplace:: PExpr -> Maybe PExpr That for ...
Christian C.'s user avatar
2 votes
1 answer
106 views

Haskell - Function not working with infinite lists [duplicate]

I wrote a function which cuts a list into half in every possible way. My problem is that I used the 'lenght' function so it can't work with infinite lists. I couldn't think of anything that actually ...
3t893w's user avatar
  • 297
2 votes
4 answers
298 views

Why isn't (20 >) . length . take 10 === const True

tl;dr Isn't the fact that 20 < length $ take 10 $ whatever requires whatever to successfully pattern patch a list (at least either [] or (_:_)) a "lack" of laziness? Or, in other words, ...
Enlico's user avatar
  • 28.9k
1 vote
1 answer
116 views

Function expects Char in place of [Char]

I am new to Haskell and functional programming, and can't understand why this function cannot identify the correct type: mformat :: [Char] -> [Char] -> [Char] mformat first last = ((formatted ...
StealthyPanda's user avatar
1 vote
1 answer
452 views

How can I use a type annotation to specify a variable in Haskell?

I am running test cases for functions I created in Haskell. I created a function called zip3Lists. It takes in any type (polymorphic arguments) of three lists and returns list of 3-tuples where each 3-...
user avatar
1 vote
1 answer
353 views

pattern matching of negative literals in Haskell

I was trying to understand why n + k patterns were banned in Haskell. A famous post on StackOverflow gives an example of a function as follows: f 0 = 0 f (n + 5) = 5 Haskell shows an error while ...
Caelan Miron's user avatar
-1 votes
1 answer
74 views

Haskell - A problem with non-exhaustive patterns in function

I have the following haskell code: Why doesn't x0's pattern matching to function f?
123's user avatar
  • 39
1 vote
2 answers
216 views

Haskell - Number of occurencies of a Char in a String [duplicate]

I am writing a function in Haskell to count the occurencies of a Char value in a String, but getting an error with the pattern matching. Is there any way I could change the pattern matching to check ...
123's user avatar
  • 39
-1 votes
1 answer
71 views

Generic Pattern in Haskell

I was hoping that Haskell's compiler would understand that f v Is type-safe given Unfold v f (Although that is a tall order). data Sequence a = FirstThen a (Sequence a) | Repeating a | UnFold b (b -&...
user avatar
3 votes
1 answer
233 views

Transpose nested data structures

I need a function like Vector [Vector a] -> Vector [Vector a], where everything stays within the same list-index, but (for each list-index) the i-th element of the j-th inner-vector becomes the j-...
ShapeOfMatter's user avatar
1 vote
1 answer
199 views

Is there a way to use "<=" for pattern matching in Haskell?

I have the following code, that drops every nth element in a list. dropEvery :: [a] -> Int -> [a] dropEvery xs n = f xs n ++ dropEvery (drop n xs) n where f ys 0 = [] f ys 1 =...
diffdaff's user avatar

15 30 50 per page
1
2 3 4 5