这是我的代码
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.
答案 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]
。