PS C:\Users\narut\OneDrive\Desktop\Monash\Year 2\Semester…
- User
PS C:\Users\narut\OneDrive\Desktop\Monash\Year 2\Semester 2\FIT2102\Assignments\Assignment 2\Assignment 2 - Updated 29 Sep\Haskell> stack test exercises> build (lib + exe + test) with ghc-9.2.8 Preprocessing library for exercises-0.1.0.0.. Building library for exercises-0.1.0.0..
: warning: [-Wunused-packages] The following packages were specified via -package or -package-id flags, but were not needed for compilation: - time-1.11.1.1 [3 of 4] Compiling Assignment
src\Assignment.hs:45:8: error: • Couldn't match expected type: Char -> Parser a1 with actual type: Parser Char • The function ‘char’ is applied to one value argument, but its type ‘Parser Char’ has none In a stmt of a 'do' block: _ <- char '[' In the expression: do _ <- char '[' linkText <- some (noneof "]") _ <- string "](" url <- some (noneof ")") .... | 45 | _ <- char '[' | ^^^^^^^^
src\Assignment.hs:49:8: error: • Couldn't match expected type: Char -> Parser a2 with actual type: Parser Char • The function ‘char’ is applied to one value argument, but its type ‘Parser Char’ has none In a stmt of a 'do' block: _ <- char ')' In the expression: do _ <- char '[' linkText <- some (noneof "]") _ <- string "](" url <- some (noneof ")") .... | 49 | _ <- char ')' | ^^^^^^^^
src\Assignment.hs:54:35: error: • Couldn't match expected type: Char -> Parser a0 with actual type: Parser Char • The function ‘char’ is applied to one value argument, but its type ‘Parser Char’ has none In the first argument of ‘(*>)’, namely ‘char '
'’ In the first argument of ‘(<*)’, namely ‘char '' *> some (noneof "")’ | 54 | parseInlineCode = InlineCode <$> (char '' *> some (noneof "") <* char '') | ^^^^^^^^src\Assignment.hs:54:68: error: • Couldn't match expected type: Char -> Parser b0 with actual type: Parser Char • The function ‘char’ is applied to one value argument, but its type ‘Parser Char’ has none In the second argument of ‘(<*)’, namely ‘char '
'’ In the second argument of ‘(<$>)’, namely ‘(char '' > some (noneof "") <* char '')’ | 54 | parseInlineCode = InlineCode <$> (char '' *> some (noneof "") < char '`') |
^^^^^^^^ Progress 1/2Error: [S-7282] Stack failed to execute the build plan.
codeWhile executing the build plan, Stack encountered the error: [S-7011] While building package exercises-0.1.0.0 (scroll up to its section to see the error) using: C:\Users\narut\AppData\Roaming\stack\setup-exe-cache\x86_64-windows\Cabal-simple_CKvAmRb3_3.6.3.0_ghc-9.2.8.exe --verbose=1 --builddir=.stack-work\dist\6f82b39a build lib:exercises exe:main test:batch --ghc-options " -fdiagnostics-color=always" Process exited with code: ExitFailure 1 - Assistant
The errors you are encountering relate to the usage of the
charfunction in your Haskell code. Thecharfunction in a typical parser combinator library, such as Parsec or similar, is usually intended to be used with zero arguments and directly produces a parser for a specific character.Here's a breakdown and how you might fix each issue:
-
Error related to
char '['andchar ')':- The
charfunction is a parser already expecting no additional function arguments. It is meant to parse a single character. You should be using it directly in your parser pipeline rather than trying to give it a parameter (as your code suggests it might have been incorrectly used).
- The
-
- User
• Couldn't match expected type: Char -> Parser a0 with actual type: Parser Char • The function ‘char’ is applied to one value argument, but its type ‘Parser Char’ has none In the first argument of ‘(*>)’, namely ‘char '
'’ In the first argument of ‘(<*)’, namely ‘char '' *> some (noneof "`")’typecheck(-Wdeferred-type-errors) char :: Parser Char Defined at C:\Users\narut\OneDrive\Desktop\Monash\Year 2\Semester 2\FIT2102\Assignments\Assignment 2\Assignment 2 - Updated 29 Sep\Haskell\src\Parser.hs:41:1 - Assistant
The error message indicates that there's a type mismatch when you're trying to use the
charfunction in your parser combinator code. Specifically, it's stating thatcharhas the typeParser Char, but it's being used as if it's a function expecting aCharparameter.Based on the information provided, it appears that your
charfunction is defined insrc\Parser.hsas:haskellchar :: Parser Char - User
this is how it is implemented, and you cannot change it, so work around it:
char :: Parser Char char = Parser f where f "" = Error UnexpectedEof f (x : xs) = Result xs x
- Assistant
Given the fixed implementation of
charas a parser that reads a single character from the input string, you'll need to work within these constraints to achieve the desired functionality. Here is how you can adapt your code to use this version ofchar.You need to assume that
charalways successfully consumes one character from the input. Therefore, if you want to parse a specific character, you'll need to check the parsed result against that character.Here's a possible workaround using your version of
char:-
Define a Helper Function: You can define a helper function that takes a character and only succeeds if that character matches the next character in the input:
-
- User
- Assistant