Posts by luispauloml • 482 points
11 posts
-
1
votes3
answers244
viewsA: Exception: Non-exhaustive Patterns in Function - Haskell
This error happens when it is not possible to match the function input with any of the defaults defined for the function, and this happened because there is an error in the fourth line of your…
haskellanswered luispauloml 482 -
1
votes1
answer81
viewsA: Polymorphism with list comprehension in Haskell
Yes, it is possible and its function is almost correct. Its implementation of sequencia uses the operator >= and the syntactic sugar [i..j]. In case you don’t know, syntactic sugar is a syntax of…
haskellanswered luispauloml 482 -
1
votes1
answer92
viewsA: Questions with tail recursion in Haskell
Assuming you already know what a tail recursion is (in case you didn’t know, I recommend reading it this answer), the argument 1 against there only to ensure that the fataux be called correctly. In…
haskellanswered luispauloml 482 -
0
votes1
answer69
viewsA: How to declare type in a function in Haskell?
To declare the type of a function you must: define the function and allow the GHC to deduct the type on its own account, or define the type and the function in the same file. It is likely that you…
haskellanswered luispauloml 482 -
2
votes2
answers117
viewsA: How to use guards with Let in Haskell
You have to use expressions case. For example: raizes2 :: Float -> Float -> Float -> (Float, Float) raizes2 a b c = let delta = (b^2 - 4*a*c) in case compare delta 0 of LT -> error…
haskellanswered luispauloml 482 -
5
votes2
answers4189
viewsA: How to generate the alphabet with white space between letters?
The module Data.List has the function intersperse that does just that. See in Ghci: Prelude> :m + Data.List Prelude Data.List> intersperse ' ' ['a'..'z'] "a b c d e f g h i j k l m n o p q r s…
-
3
votes1
answer303
viewsA: How to pick the first item from each list from a list list
It is possible to create such a function using more general functions such as map, fst, snd and splitAt, all continas in Prelude. primeiros :: [[a]] -> [[a]] primeiros xs = helper1 ([], xs)…
haskellanswered luispauloml 482 -
3
votes1
answer41
viewsA: Doubt Error Tree in Haskell
You are correct in your suspicion. The keyword type should not have been used in this case. The correct is data. Briefly: In Haskell, we have three basic ways to type: Using data for new types.…
-
2
votes1
answer276
viewsA: How to call an assist function without passing the parameter through the main function
As you yourself noticed, you should call the bank somehow. The most common solution make use of currying and flip with the function buscarDBaux to raise buscarDB, or reorder the arguments of…
haskellanswered luispauloml 482 -
5
votes1
answer55
viewsA: Guards vs functions with Pattern matching
First of all, your job is to use guards (Guards), while that of the other participant uses pattern marriage (patter matching). In addition, both will always have the same results and are…
-
3
votes1
answer61
viewsA: Save function status in Haskell
Haskell is a purely functional language. It is impossible to save the state of something. The only way to achieve what you want is to pass to a function two things at once: the previous state of the…
haskellanswered luispauloml 482