D4IVT3
D4IVT3

Reputation: 95

haskell error parse error (possibly incorrect indentation)

this is my code

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 = "*"

and i had and this error in convertir:

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

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

Upvotes: 0

Views: 417

Answers (1)

AndrewC
AndrewC

Reputation: 32475

Why the error

Every (normal) guard is of the form

    | boolean expression = value

You missed this out for your otherwise cases. It works like this because otherwise is defined as

otherwise = True

so it's not a keyword like else, it's just a human-readable "always", and since the guards are tried top-to-bottom, this is a catch-all for anything that wasn't true above.

Some corrections

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) 

here:

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

and here:

              | 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 = "*"

Some abbreviations

By the way,

  • ["*****","*****","*****","*****","*****","*****","*****"] is replicate 7 "*****" and
  • map trns (map rInt (map show b)) is map (trns.fInt.show) b.
  • Also [tail(e1),tail(e2),tail(e3),tail(e4)] is map tail [e1,e2,e3,e4,e5]
  • but I think you have a type error with :e5, because it has to be a list of lists in the pattern (e1:e2:e3:e4:e5) but you've used it like an element tail(e5).
  • Also [(psr(head(e1)))++(psr(head(e2)))++(psr(head(e3)))++(psr(head(e4)))++(psr(head(e5)))] is map (psr.head) [e1,e2,e3,e4,e5].

Upvotes: 2

Related Questions