Questions tagged as 'haskell'

1
answer

What is the difference between [a] and "a" in Haskhell?

Is this correct? [a] = a list with 1 single element a = a list with as many elements as you want Ps: I have some doubts because some functions are of type [a]->a but also read, for example [2,3]     
asked by 07.10.2017 / 19:40
1
answer

Define a function with different quantities of arguments

There is some reason for this function: foo f x y = f x y foo x y = (+) x y Return this error?    Equations for 'foo' have different numbers of arguments Why does not Haskell allow this behavior?     
asked by 18.09.2015 / 03:55
1
answer

How to use Monad batteries?

I studied the topic of Monad and decided to make a program to test my knowledge. import Control.Monad.IO.Class (liftIO) import qualified Control.Monad.State as ST import Control.Monad.Trans.State (StateT (..), e...
asked by 09.02.2017 / 16:05
1
answer

Doubt about functions in Haskell

I decided to dive into the world of functional programming recently, and was introduced to the Haskell language. I started researching how language works, and soon I got the key concepts. So I started working with lists, and decided to reimpleme...
asked by 21.03.2017 / 18:02
1
answer

Creating files in Haskell

I wanted to record the output of my program straight into a file. When I ran the code, it automatically generated a file with the output of this code instead of printing it on the screen. A simple example: func = do writeFile "file.txt" sh...
asked by 24.07.2014 / 10:34
0
answers

How to compare two strings in haskell?

buscaLivroNome :: Livro -> Nome -> String buscaLivroNome [] _ = "Nao Encontrado" buscaLivroNome ((codigo,nome1,preco, autor, ano):resto) nome2 | nome1 == nome2 = "Livro Encontrado" | otherwise = buscaLivroNome resto nome2 I need to compa...
asked by 11.08.2017 / 20:24
1
answer

Guards vs. functions with pattern matching

I'm starting at Haskell and doing her exercises on Exercism . When I sent a code, I was comparing it with others and I came across a similar one to mine, but I used a definition of guards (I do not know if it is guard I saw in a place calli...
asked by 19.01.2018 / 22:30
1
answer

How to get the first item from each list in a list of lists

I'm new to programming in Haskell, and wanted to know a way to get the first item from each list and put it on a list, then the second, then the third, and so on ... An example would be more less the following: Input: [[1,1,1,1],[2,2,2,2],[3,3...
asked by 01.07.2018 / 21:12
1
answer

How to change the typing in Haskell

I want the function to draw a number, and if it is greater than 7, send an approval message and call this add function. However, my function only falls on the 'else'. The "disapproved" message appears. I think it's the IO Float typing with Float...
asked by 09.12.2017 / 07:55
1
answer

Elements of a List are all the same

I made this function definition equal, which checks to see if all the elements of a list are equal. iguais :: [Float] -> Bool iguais [x,y] = x == y iguais (h:t) = h == (head t) However, the result is not what you want. Can you tell...
asked by 18.12.2017 / 17:30