Problem with calling a Haskell function from the main module

I defined a function called findPathsin a Haskell module called BinaryTree, and I'm trying to call this function in the main module that I created. Type of function call

findPaths :: Tree -> [Path]

Where Treeis the data type defined as:

data Tree = Leaf | Node Tree Tree

and is Pathdefined as:

data Path = LeftTurn Path | RightTurn Path | This

In the main function, I do this and only this:

module Main where
import BinaryTree
findPaths (Node Leaf Leaf)

But when I try to compile it with the following command:

ghc -o --make Main Main.hs BinaryTree.hs

I get this error:

Couldn't match expected type `Language.Haskell.TH.Syntax.Q
                                    [Language.Haskell.TH.Syntax.Dec] '
against inferred type `[Path] '
In the expression: findPaths (Node Leaf Leaf)

I get the same error if I try to export data types in the BinaryTree module:

module BinaryTree (Tree(..), Path(..), allPaths) where...

... , . , , , . .

UPDATE

, , .

@Travis , , , :

import BinaryTree

main = do
    print (findPaths (Node Leaf Leaf))

, . , .

2

, , , , . , , . , .

+3
3

, findPaths (Node Leaf Leaf) Main, .

GHC, , , :

travis@sidmouth% echo '"Hello world"' > Test.hs
travis@sidmouth% ghc Test.hs

Test.hs:1:0:
    Couldn't match expected type `Language.Haskell.TH.Syntax.Q
                                    [Language.Haskell.TH.Syntax.Dec]'
           against inferred type `[Char]'
    In the expression: "Hello world"

, GHC , Template Haskell, - . , , . :

module Main where
import BinaryTree
paths = findPaths (Node Leaf Leaf)
main = putStrLn "Do something here."
+3

, Jonno_FTW, main , IO. , Main.hs :

module Main where
import BinaryTree
main = putStrLn . show . findPaths $ Node Leaf Leaf
+4

, ghc, :

ghc -o main --make Main.hs
+2

Source: https://habr.com/ru/post/1768740/


All Articles