Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell... parse error on module

what can be wrong with this? I've tried multiple solutions but it all ends up with the error on 'module' and in the = sign after the main. what the heck?!?!?!

printTabuleiro :: [[Char]] -> IO()
printTabuleiro [] = []
printTabuleiro (l :lt) = putStr l : printTabuleiro lt

module Main where

main = let 
          a = ["#####\n","###o##\n"] 
       in do printTabuleiro a

now I get this compiling errors, I do not understand the type matching issues here. Btw, I'm fairly new and not used to functional don't cannonize me to mars please.

[1 of 1] Compiling Main             ( visualisacao.hs, interpreted )

visualisacao.hs:14:27:
    Couldn't match expected type ‘IO ()’ with actual type ‘[IO ()]’
    In the expression: putStr l : printTabuleiro lt
    In an equation for ‘printTabuleiro’:
        printTabuleiro (l : lt) = putStr l : printTabuleiro lt

visualisacao.hs:14:38:
    Couldn't match expected type ‘[IO ()]’ with actual type ‘IO ()’
    In the second argument of ‘(:)’, namely ‘printTabuleiro lt’
    In the expression: putStr l : printTabuleiro lt
Failed, modules loaded: none.
like image 834
baitillus Avatar asked Nov 30 '22 17:11

baitillus


2 Answers

You need to declare your module first. Then you need to declare your imports. Then you can define your functions.

like image 100
mac10688 Avatar answered Dec 05 '22 04:12

mac10688


The module declaration can only be preceded by comments and compiler pragmas like language extensions. Put the module Main where line at the top of your file and everything else below it. Imports must also come between the module declaration and any function or type declarations, so it should look like

module Main where

import Data.Char
import ...

printTabuleiro :: ...
printTabuleiro [] = ...

main = let
         a = ...
    in do printTabuleiro a
like image 20
bheklilr Avatar answered Dec 05 '22 05:12

bheklilr