haskell错误解析错误(可能是错误的缩进)

时间:2014-03-01 14:33:05

标签: haskell

这是我的代码

font a = let x= ord a in
        if x>=0 || x<=31 || x>=126 then ["*****","*****","*****","*****","*****","*****","*****"]
        else
            auxfont (fontBitmap!!(x-32))
            where
            auxfont b = let y = map trns (map rInt (map show b)) in
                       convertir y []
            trns z = modA [] 1 z
            modA o l k
                  | l < 8 = modA (o++[(k `mod` 2)]) (l+1) (k `div` 2) 
                  | otherwise o           
            convertir (e1:e2:e3:e4:e5) f 
                  | e1==[]  = f
                  | otherwise convertir [tail(e1),tail(e2),tail(e3),tail(e4),tail(e5)] (f++[(psr(head(e1)))++(psr(head(e2)))++(psr(head(e3)))++(psr(head(e4)))++(psr(head(e5)))])
            psr 0 = " "
            psr 1 = "*"

我在转换中遇到了这个错误:

[1 of 2] Compiling Pixels           ( Pixels.hs, interpreted )

Pixels.hs:122:13: parse error (possibly incorrect indentation)
Failed, modules loaded: none.

1 个答案:

答案 0 :(得分:2)

错误原因

每个(正常)后卫的形式为

    | boolean expression = value

您错过了otherwise个案例。它的工作原理如下,因为otherwise被定义为

otherwise = True

因此它不是像else那样的关键字,它只是一个人类可读的“永远”,并且由于守卫是从上到下进行的,所以对于任何不真实的事情都是如此上方。

一些更正

font a = let x= ord a in
        if x>=0 || x<=31 || x>=126 then ["*****","*****","*****","*****","*****","*****","*****"]
        else
            auxfont (fontBitmap!!(x-32))
          where
            auxfont b = let y = map trns (map rInt (map show b)) in
                       convertir y []
            trns z = modA [] 1 z
            modA o l k
                  | l < 8 = modA (o++[(k `mod` 2)]) (l+1) (k `div` 2) 

这里:

              | otherwise = o       -- added =
        convertir (e1:e2:e3:e4:e5) f 
              | e1==[]  = f

在这里:

              | otherwise = convertir [tail(e1),tail(e2),tail(e3),tail(e4),tail(e5)] (f++[(psr(head(e1)))++(psr(head(e2)))++(psr(head(e3)))++(psr(head(e4)))++(psr(head(e5)))])
        psr 0 = " "
        psr 1 = "*"

一些缩写

顺便说一下,

  • ["*****","*****","*****","*****","*****","*****","*****"]replicate 7 "*****"
  • map trns (map rInt (map show b))map (trns.fInt.show) b
  • 此外[tail(e1),tail(e2),tail(e3),tail(e4)]map tail [e1,e2,e3,e4,e5]
  • 但我认为:e5存在类型错误,因为它必须是模式(e1:e2:e3:e4:e5)中的列表列表,但您已将其用作元素tail(e5)
  • 此外[(psr(head(e1)))++(psr(head(e2)))++(psr(head(e3)))++(psr(head(e4)))++(psr(head(e5)))]map (psr.head) [e1,e2,e3,e4,e5]
相关问题