Haskell: parse error on input `|' - haskell

I am getting this error:
sky.hs:3:5: error: parse error on input `|'
This is the code:
sky list
| (length list) /= 1 = reverse (last(even (sky list)) : reverse(odd list)
| otherwise = list
Does anyone have any idea why this is happening? I have made sure that there are no tabs, just 4 spaces before the | symbol. This might seem like a novice question but I am a beginner in Haskell.

Related

Parse Error (Possibly Incorrect Indentation...)

When I run this code:
test1 :: Int -> String
test1 x = do
if x == 1
then "Hello"
I get the following error:
test-if.hs:4:21: error:
parse error (possibly incorrect indentation or mismatched brackets)
I am not sure why this is as I am not using any brackets and I am using 4 spaces as my tabs. Adding brackets doesn't seem to help. What could be the issue?
Thanks
Your if needs an else (what do you want the value to be when x isn't 1?).
Furthermore do notation is used when working with monads and doesn't make sense in this function.

Input length restriction in GHCi

I programmed kakuro-solver, but I have problem with user's input. When user want to enter input longer then 1024 chars, haskell trims input and throws exception
<interactive>:9:1024:
parse error (possibly incorrect indentation or mismatched brackets)
For example I want to enter this input
kakuro [(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-1,0,6),(-1,0,23),(-2,0,0),(-2,0,0),(-1,0,7),(-1,0,23),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-1,0,18),(-1,0,12),(-2,0,0),(-1,0,12),(-1,0,26),(-1,9,0),(0,0,0),(0,0,0),(-2,0,0),(-1,13,19),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-1,7,23),(0,0,0),(0,0,0),(-1,3,0),(0,0,0),(0,0,0),(-1,5,16),(0,0,0),(0,0,0),(-1,18,10),(0,0,0),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-1,7,0),(0,0,0),(0,0,0),(0,0,0),(-1,10,0),(0,0,0),(0,0,0),(0,0,0),(-1,21,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-1,20,15),(0,0,0),(0,0,0),(0,0,0),(-1,24,0),(0,0,0),(0,0,0),(0,0,0),(-1,11,20),(0,0,0),(0,0,0),(0,0,0),(-1,0,17),(-2,0,0),(-2,0,0),(-1,14,0),(0,0,0),(0,0,0),(-1,0,23),(-1,0,12),(-1,0,15),(-1,20,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(-1,10,0),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-1,26,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(-1,0,13),(-2,0,0),(-1,13,19),(0,0,0),(0,0,0),(-1,13,0),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-1,33,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(-1,15,30),(0,0,0),(0,0,0),(-1,0,16),(-2,0,0),(-2,0,0),(-1,0,21),(-1,0,29),(-2,0,0),(-2,0,0),(-1,16,0),(0,0,0),(0,0,0),(-2,0,0),(-1,31,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(-1,0,12),(-1,17,13),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-1,0,11),(-1,0,23),(-2,0,0),(-1,10,37),(0,0,0),(0,0,0),(-1,26,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(-1,0,11),(-2,0,0),(-2,0,0),(-1,4,0),(0,0,0),(0,0,0),(-1,16,0),(0,0,0),(0,0,0),(-1,0,9),(-1,0,16),(-1,34,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-1,17,0),(0,0,0),(0,0,0),(-1,18,14),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(-1,0,13),(-2,0,0),(-1,0,20),(-1,4,13),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-1,0,7),(-1,18,21),(0,0,0),(0,0,0),(0,0,0),(-1,21,0),(0,0,0),(0,0,0),(0,0,0),(-1,22,0),(0,0,0),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-1,33,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(-1,6,17),(0,0,0),(0,0,0),(0,0,0),(-1,9,0),(0,0,0),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-1,8,0),(0,0,0),(0,0,0),(0,0,0),(-1,13,0),(0,0,0),(0,0,0),(-1,3,0),(0,0,0),(0,0,0),(-1,16,0),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-1,11,0),(0,0,0),(0,0,0),(-2,0,0),(-1,17,0),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0)]
but WinGHCi trims it to
kakuro [(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-1,0,6),(-1,0,23),(-2,0,0),(-2,0,0),(-1,0,7),(-1,0,23),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-1,0,18),(-1,0,12),(-2,0,0),(-1,0,12),(-1,0,26),(-1,9,0),(0,0,0),(0,0,0),(-2,0,0),(-1,13,19),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-1,7,23),(0,0,0),(0,0,0),(-1,3,0),(0,0,0),(0,0,0),(-1,5,16),(0,0,0),(0,0,0),(-1,18,10),(0,0,0),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-1,7,0),(0,0,0),(0,0,0),(0,0,0),(-1,10,0),(0,0,0),(0,0,0),(0,0,0),(-1,21,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-1,20,15),(0,0,0),(0,0,0),(0,0,0),(-1,24,0),(0,0,0),(0,0,0),(0,0,0),(-1,11,20),(0,0,0),(0,0,0),(0,0,0),(-1,0,17),(-2,0,0),(-2,0,0),(-1,14,0),(0,0,0),(0,0,0),(-1,0,23),(-1,0,12),(-1,0,15),(-1,20,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(-1,10,0),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-1,26,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(0,0,0),(-1,0,13),(-2,0,0),(-1,13,19),(0,0,0),(0,0,0),(-1,13,0),(0,0,0),(0,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-1,33,0),(0,0,0)
I tried use monad, but there is the same problem, I have to split input to more lines.
Is there any options, how enter inputs longer then 1024 chars?
Sure:
λ> :{
| let result =
| kakuro [
| (-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),(-2,0,0),
| (-2,0,0),(-2,0,0),(-1,0,6),(-1,0,23) ...
| -- AND SO ON...
| ]
| :}
And then just evaluate result.
However, I imagine that you've taken the list from the result of a previous command. In GHCi, the result of the previous expression is it, so you could probably write kakuro it. If you haven't done that, then read it from a file:
λ> kakurodata <- read `fmap` readFile "/file/data/here.txt"
λ> kakuro kakurodata
EDIT: #Carsten pointed out that you could just plonk it in a file and :load it. Thanks!

Why complains Haskell parse error on input `|' in this Function?

I was supposed to write a little function in Haskell, which should erase elements, which are twice in the list. Unfortunately, Haskell complains " parse error on input `|' ". Could anyone help me with that?
makeSets=mSet[]s
where
mSet stack []=stack
mSet stack (x:xs)
|contains stack x=mSetstack xs
| otherwise =mSet (x:stack) xs
where
contains [] thing=False
contains (x:xs)thing
| x==thing=True
|otherwise=contains xs thing
You are mixing tabs and spaces, which is no good when indentation is significant. Use either all spaces (strongly recommended), or all tabs.

Error : parse error on input `='

I'm reading the Haskell book : http://learnyouahaskell.com/types-and-typeclasses
When I enter this line in the interpreter,
removeNonUppercase st = [c | c <- st, c `elem` ['A' .. 'Z']]
I get this error:
parse error on input `='
Whats causing this error ?
When defining variables or functions in the interpreter or in a GHCi script file (i.e. not a Haskell module), you need to use the let keyword.
> let removeNonUppercase st = [c | c <- st, c `elem` ['A' .. 'Z']]
This is because the interpreter essentially acts as if you were in a global do-block. Your code would be OK as-is in a Haskell source file.
If you got this error outside the interpreter, you probably either messed up the indentation, or you have some other syntax error in nearby code.

Haskell error on input `|' Failed no modules

I'm pretty new in Haskell and I have got a very strange mistake:
insertion el [] = [el]
insertion el (x:xs) = | el < x = el:x:xs
| otherwise = x:insertion el xs
Which gives me this error, on the second line at the caractere just after the pipe:
parse error on input `|'
Failed, modules loaded: none.
I don't really get it,
would you have a tips ?
Thanks in advance :)
When you use guards (the pipe symbol) with function definitions, you do not follow the function name and paramaters with an equal sign. It should be written like this:
insertion el [] = [el]
insertion el (x:xs)
| el < x = el:x:xs
| otherwise = x:insertion el xs
The first guard doesn't need to be on the next line, but that tends to be the general style.

Resources