haskell - How to compare string to value without quotation marks -


i pretty new haskell , today trying make calculator using haskell (like people make when learning new language hold of if statements) , had trouble using if values strings. want check if string user wrote "plus" (without "") if don't quotation marks (so it'd if op == plus) doesn't recognize string , outputs error if on other hand use quotation marks (so it'd if op == "plus") looks string "plus" quotation marks, how can compare string value without quotation marks?

case 1:

calculate x op y =             if op == "plus"                         x+y                         else x 

result: program looks "plus" when calling function , if input when calling function example "1 plus 3" give out error of ':67:13: error: variable not in scope: plus :: [char]

case 2:

calculate x op y =             if op == plus                         x+y                         else x 

result: when trying load program error "test.hs:2:33: error: variable not in scope: plus failed, modules loaded: none.", can't try , call function obviously.

the quotation marks part of syntax of string literals, not contents. is, if write op == "plus", true if (and if) plus contains characters 'p', 'l', 'u' , 's' (in order, obviously) - not require (or allow) op contain quotes.

so if op == "plus" not produce true when think should, op not contain think does.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -