Lexical fault when using ''BOOM!'' [closed] - haskell

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I type this into my texteditor:
boombang xs = [ if x < 10 then ”BOOM!” else ”BANG!”
But when trying to load it, my terminal denies it and and says:
Probably some dumb rookie mistake, but I can't seem to find the solution...:/

There are two problems here.
The first is, you're not using plain ASCII quotation marks (U+0022) ". You're using right quotation marks (U+201D) ”. There's probably a keyboard setting you're using that's causing this, and using certain text editing programs can also prevent this.
Secondly, you seem to be either missing a right bracket. As pointed out, this is probably meant to be part of a list comprehension. You need to write all of the list comprehension for it to work.
The corrected code is:
boombang xs = [if x < 10 then "BOOM!" else "BANG!" | x <- xs]

Related

I migrated from python 2.7 to 3.8.5, now my code won't run. I am showing UnboundLocalError: local variable 'Url_name' referenced before assignment [duplicate]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Python:
I have researched a lot into this, but as a beginner I don't understand the solutions, let alone apply them to my simple problem:
def min_max(xs):
xs = []
for i in xs:
y = (min, max)
return y
"local variable 'y' referenced before assignment"
I don't understand why this does NOT work!!
I've defined Y in the line before return, i know there is another way to do it, but i really need to know why this method is wrong!
Thanks!
assuming that min and max are defined somewhere else....
The loop for i in xs will go around once for each item in xs. Since xs is empty, the loop will not run at all. So, y is never set.

Syntax error in Break statement in Python - help needed [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am beginner in Python so I have been experiencing some issues in loops if python. My concerns involves 'while' loop and 'break' statement.
I have followed as it is mentioned in book and also cross verified from internet but my code does not work still gives me same error.
for i in range(5): j=j+2
print('i:',i, ',j:',j) if j==6:break
Gives me error as below
File "<ipython-input-5-5ff0ac309f49>", line 5
print('i:',i, ',j:',j) if j==6:break
^
SyntaxError: invalid syntax
In python leading spaces in a meaningful. This code works well.
j=0
for i in range(5):
j=j+2
print('i:',i, ',j:',j)
if j==6:
break
You have to use correct indents in python. Since there are no concept of braces, if you want a block to be in a scope, the indents matter. You can refer to this example
Your code in correction will look like:
j = 0
for i in range(5):
j = j + 2
print('i:', i, ',j:', j)
if j == 6:
break
basically, think like every bracket is like a new line+ 4 space indents.

How to I properly use the min function in Haskell code? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
main = print $ smallestFactor 15
factors n = [x | x <- [2..n], n `mod` x == 0]
smallestFactor n = min[factors n]
I understand that it's a pretty trivial question but someone told me that I could use min get grab out the smallest value of a element list. Though, I'm not exactly sure how one is suppose to use it.
You mean minimum :: Ord a => [a] -> a. Plus, you're erroneously using square brackets when you should be using parentheses. Don't use square brackets when you're not explicity defining a list!
Here's the corrected part:
smallestFactor n = minimum (factors n)
The rest of your code is fine.

Error Message "Perhaps you intended to use TemplateHaskell " [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I tried to use to infix expression for div function as follows:
92 'div' 10
The following error message popped out:
Syntax error on 'div'
Perhaps you intended to use TemplateHaskell
In the Template Haskell Quotation 'div'
Those look like quotes (') and not back ticks (`) to me, which is why the compiler is confused. The infix expression uses the back ticks (left of 1 on most keyboards).

Using do notation with if/else [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I'm trying to use do notation to only return a list element if it's even:
ghci> do { x <- [1,2,3]; if (even x) [x] else []}
<interactive>:43:36: parse error on input `else'
What am I doing wrong?
In addition, please note if this code is non-idiomatic.
You forgot the "then".
Also, i'm not really sure which Monad is this..
do { x <- [1,2,3]; if (even x) then [x] else []}

Resources