first time working with haskell and I keep running into this issue:
Couldn't match expected type `([Char], b0)'
with actual type `[[Char]]'
In the first argument of `fst', namely `moves'
In the second argument of `rotatedMaze', namely `(fst moves)'
I can't quite figure out what is going on. Where is my parameter error?
manyPlayersManyRotations :: [[Char]] -> [[Char]] -> [[Char]]
manyPlayersManyRotations maze moves =
if null moves
then maze
else
let
rmaze = rotatedMaze maze (fst moves)
drop1 = dropPlayer rmaze '1'
opor1 = (fst drop1, snd drop1)
drop2 = dropPlayer (fst opor1) '2'
opor2 = (fst drop2, snd opor2 || snd drop2)
drop3 = dropPlayer (fst opor2) '3'
opor3 = (fst drop3, snd opor2 || snd drop3)
drop4 = dropPlayer (fst opor3) '4'
opor4 = (fst drop4, snd opor2 || snd drop4)
in
if (not)(snd opor4)
then fst opor4
else manyPlayersManyRotations (fst opor4) (tail moves)
rotatedMaze :: [[Char]] -> [Char] -> [[Char]]
rotatedMaze maze move =
if move == ['c']
then rc maze
else if move == ['c','c']
then rcc maze
else r180 maze
fst
wants a tuple, but you gave it a list.
The type of fst
is:
fst :: (a, b) -> a
The first line of the error message
Couldn't match expected type `([Char], b0)'
says the expected type for the argument in your call to fst
is ([Char], b0)
. The [Char]
bit is inferred from context, and b0
just means it doesn't care what that second type is (because fst
just discards the second tuple element).
The second line of the error message
with actual type `[[Char]]'
says you passed it a [[Char]]
instead, because... well, that's what you've done.
Perhaps what you meant instead of fst
is head
, which gives the first element of a list.
fst
和snd
是为2元组定义的,这里的参数是列表[[Char]]
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.