readSquareTransition :: String -> Maybe [SquareTurn]
readSquareTransition [] = Just []
readSquareTransition (x:xs) = case x of
'L' -> Just (L : readSquareTransition xs)
'R' -> Just (R : readSquareTransition xs)
_ -> Nothing
我想要得到只是[L,L,R,R]。不過貌似我沒:(以下是錯誤信息!Haskell String to Maybe List
src/StudentSources/LangtonsAnt.hs:231:24:
Couldn't match expected type ‘[SquareTurn]’
with actual type ‘Maybe [SquareTurn]’
In the second argument of ‘(:)’, namely ‘readSquareTransition xs’
In the first argument of ‘Just’, namely
‘(L : readSquareTransition xs)’
src/StudentSources/LangtonsAnt.hs:232:24:
Couldn't match expected type ‘[SquareTurn]’
with actual type ‘Maybe [SquareTurn]’
In the second argument of ‘(:)’, namely ‘readSquareTransition xs’
In the first argument of ‘Just’, namely
‘(R : readSquareTransition xs)’
你不得不放棄'Just':'readSquareTransition'已經返回一個Maybe的東西。 – gallais
糟糕,我正在粗心大意,你是對的,我會改變這個...... – jamshidh
你應該在'readSquareTransition xs'或$''前面加括號,或者使用中綴'(<$>)'代替'fmap'。 – gallais