Questions tagged as 'haskell'

1
answer

Could not match expected type 'Double' with current type 'Integer'

Code haskell: bin2dec::[Integer]->Integer bin2dec (h:[]) = h bin2dec (h:t) = h*(2^length(t))+bin2dec(t) bin2frac :: ([Integer], [Integer]) -> Double bin2frac(x,y) = fromDouble(bin2dec(x)) * 10 ^ bin2dec(y) Goal: Define a recursive...
asked by 07.06.2015 / 01:05
1
answer

How can I change the code I made for a recursion

This was the initial code I made: count :: Char → String → Int count x xs = length [x’ | x’← xs, x == x’] Change to recursion: count = length x' | x' <- xs | x == x' What am I doing wrong? Or is it even possible to change the i...
asked by 24.10.2018 / 16:01
1
answer

Recursion- elemindices

They know how to recursively define the elemindices function, pre-defined in Prelude. I defined it in a way, but it does not give the expected result. myElemIndices :: Eq a => a -> [a] -> [Int] myElemIndices x [] = [] myElemIndices x...
asked by 17.10.2017 / 22:16
1
answer

Why does this code give no error, but does not return anything?

I'm still learning Haskell (actually only started about 2 days ago) with a basic C # knowledge. In this piece of code the code is supposed to iterate several times in a list and subtract the first value from the second until it finishes. The...
asked by 06.10.2017 / 21:01
0
answers

Functional or imperative language to study Machine Learning? [closed]

I'm new to programming and I'm studying javascript to become a Front End Developer as a short-term goal, in the future I plan to be a programmer, because I'm interested in machine learning / artificial intelligence, nowadays I read several texts...
asked by 09.06.2016 / 11:10
2
answers

Retract a list without repeating them

Define a primitive recursive function capable of compressing the list by removing all elements repeated in sequence. Ex: aaabbbcddd → abcd Any ideas how to do this? I honestly do not know where to start.     
asked by 25.05.2015 / 00:41
1
answer

Why use Rational type?

Why languages like Haskell and Clojure adopt rational as type? Why would I use Rational instead of Float or Double?     
asked by 25.05.2017 / 00:31
1
answer

Doubt Error Tree in Haskell

My teacher in a haskell question asked to define tree as follows: Beingthatsettingthiswaygivesthiserror: Andinmanycornersoftheinternet,thehaskelltreetheydefineusingDataastheimagebelow: So I would like to know if the teacher is correct i...
asked by 08.04.2018 / 21:31
2
answers

How to use guards with let in Haskell

I wanted to do this same problem that calculates the roots of a second degree function, but using let. raizes2 :: Float -> Float -> Float -> (Float, Float) raizes2 a b c |delta < 0 = error "Delta nao pode ser menor que zero" |...
asked by 26.09.2018 / 20:21
1
answer

Save function state in Haskell [closed]

I want to implement a button that whenever it is clicked changes its state into haskell. If it is turned on when you press it it should hang up and vice versa. In c ++ I would save the state in a global variable, but in haskell I have no idea...
asked by 06.12.2017 / 04:49