2016-03-20 24 views
-1

ilk kez Haskell ile çalışan ve bu konuya çözüm yayınlanmaya devam:beklenen ulaşamasa tip '([Char], b0)' fiili türüyle '[[Char]]'

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)' 

elimden Neler olup bittiğini anlamaya çalışıyorum. Parametre halim nerede?

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 

cevap

5

fst bir tuple istiyor, ama sen bir liste verdin.

fst türüdür:

fst :: (a, b) -> a 

hata mesajı

Couldn't match expected type `([Char], b0)' 

ilk satırı fst çağrınızda argüman için beklenen tip ([Char], b0) olduğunu söylüyor. [Char] bit bağlamdan çıkar ve b0 sadece ikinci türün ne olduğuyla ilgilenmediği anlamına gelir (çünkü fst sadece ikinci tuple öğesini atar).

hata mesajı

with actual type `[[Char]]' 

ikinci hat şey, bu yaptığına çünkü ... Eğer bir [[Char]] yerine geçti söylüyor.

Belki de fst yerine ne demek istediyseniz, listenin ilk elemanını veren head.

2

fst ve snd senin argüman listesi [[Char]] burada, 2-dizilerini için tanımlanmıştır.

+0

Oh, teşekkürler! Orada kafa kullanmam gerektiğini unuttum. Sen bir hayat kurtarıcısın! – iHowell

İlgili konular