I think i have a problem with the parenthesces

Jackal

Im sorry i have posted codes the entire day, now i have this one and i have no idea why its not working. I have an error that doesnt tells me exactly what my problem is, someone told me to turn on the warnings so it could be easier but i dont know how do to that. If you give this code a monomian, it should give you the monomian as a string. The monomian is a (a,b), so thats why the code is full of fst and snd.

showMon :: Monomio -> String
showMon = \m -> case (fst m) == 0 of{ True -> " ";
                                    False -> case (fst m) == 1 of{ True -> case (snd m) == 0 of{ True -> "1";
                                                                                               False -> case (snd m) == 1 of{ True-> "x";
                                                                                                                            False -> "x^" ++ (show (snd m));}}
                                                                   False -> case (fst m) < 0 of{ True -> case (snd m) == 0 of{ True -> show 1;
                                                                                                                     False -> case (snd m) == 1 of { True -> "-x";
                                                                                                                                                     False -> "-x^" ++ show (snd m);}}                                                                                        
                                                                                          False -> case snd m == 0 of{ True -> show 1;
                                                                                                                       False -> case snd m == 1 of{ True-> (show fst m) ++ "x";
                                                                                                                                                    False-> (show fst m) ++ "x^" ++ show (snd m);}}}}}
Polinomios.hs:146:108: error:
    Unexpected case expression in function application:
        case (snd m) == 0 of
          True -> "1"
          False
            -> case (snd m) == 1 of
                 True -> "x"
                 False -> "x^" ++ (show (snd m))
    You could write it with parentheses
    Or perhaps you meant to enable BlockArguments?
    |
146 |                                                                     False -> case (fst m) == 1 of{ True -> case (snd m) == 0 of{ True -> "1";     | 
chi

Here's your code, re-indented for clarity. It is still quite hard to read.

showMon :: Monomio -> String
showMon = \m -> case (fst m) == 0 of
  { True -> " ";
    False -> case (fst m) == 1 of
      { True -> case (snd m) == 0 of
          { True -> "1";
            False -> case (snd m) == 1 of
              { True-> "x";
                False -> "x^" ++ (show (snd m));
              }
          } -- **
        False -> case (fst m) < 0 of
          { True -> case (snd m) == 0 of
              { True -> show 1;
                False -> case (snd m) == 1 of
                  { True -> "-x";
                    False -> "-x^" ++ show (snd m);
                  }
              } -- **
            False -> case snd m == 0 of
              { True -> show 1;
                False -> case snd m == 1 of
                  { True-> (show fst m) ++ "x";
                    False-> (show fst m) ++ "x^" ++ show (snd m);
                  }
              }
          }
      }
  }

In the points marked with -- ** above a semicolon is missing, making the compiler produce a weird error message, since we are essentially trying to apply a case expression to some arguments in this way.

Some suggestions to improve this:

You don't have to use fst,snd, you can pattern match on the input argument. Instead of \m -> ..., you can use \(m1,m2) -> ... and then use the two components directly.

You don't have to check fst m == 0, fst m == 1 in that way. You can instead use (trying to mimic your style)

case m1 of  -- recall m1 is (fst m)
  { 0 -> .... ;  -- it is 0
    1 -> .... ;  -- it is 1
    _ -> ....    -- it is something else
  }

In principle, with guards you can even incorporate checks like your fst m < 0.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I think I have problem with compiling a java file

Wordpress "I think you have a wrond seperator"

I have a problem with ModuleNotFoundError

@keyframes not working, I have tried everything i can think of

Do I actually have more RAM than I think?

I think i have done something that's setstate is not working in flutter

I think is a problem from Node but I am not sure about it

I think I have solved raster interrupts text/bitmap mode but I have this weird text error

I have annoying white space between iFrames - I have tried everything i can think of

Chloropeth map in R not working out, I think the problem is in merging the data

How to fix the "TLE" problem? I think my quicksort is OK

I think Librosa.effect.split has some problem?

How can I install more partitions, I have two I think swap and primary I guess?

I have an unknown problem with datepicker

i have facing problem with editMessageText

Why I have this problem with the appbundle?

I have a problem with ToolBar and SearchView

I have a problem with the search implementation

I have a problem with break of the programm

I have a problem with the referencing of this Script

I have a problem with if statement in javaScript

I have a problem with pytesseract on Ubuntu

I have a problem with the input() function

I have problem with spinneradapter in fragment

I have a problem with a program for a library

i have a problem with installing matplotlib

I have a problem with if statement and numbers

I have a rendering problem with useEffect

i have a problem with the importation of sql