0

I am trying to import a Haskell module named Shapes from a file called surface (which compiles fine)

import qualified surface.Shapes as Shapes

surfaceImport :: Shape -> Float
surfaceImport (Circle _ r) = pi * r ^ 2
surfaceImport (Rectangle (Point x1 x2) (Point y1 y2)) = (abs $ x1 - x2) * (abs $ y1 - y2)

I am getting the following error when I try to compile this program

surfaceImport.hs:1:18: error: parse error on input `surface'
Failed, modules loaded: none.

The module I am trying to import is this

module Shapes
(
Point(..),
Shape(..),
surface,
nudge,
baseCircle,
baseRectangle
)

Thanks in advance where

2
  • downloads.haskell.org/~ghc/7.0.3/docs/html/users_guide/… Commented Feb 22, 2017 at 7:59
  • 5
    The name of the module and the name of the file should be the same. In your case, rename the file surface to Shapes and import Shapes in your surfaceImport Module. Another problem is that you have a function called surface in your exports. Your file name and the function should not have the same name. Commented Feb 22, 2017 at 8:53

1 Answer 1

1

so first of all I think your code is from: http://learnyouahaskell.com/making-our-own-types-and-typeclasses

and there is also a part in the introduction concerning the definition of modules: http://learnyouahaskell.com/modules

It is recommended that the file and the module have the same name as stated in the link above. This will resolve your problem with the parse error on "surface". The next point that you should not do is to name your file like a function in your module.

You use a qualified import in your example. Qualified imports are explained here: https://www.haskell.org/tutorial/modules.html

In general, one uses qualified imports if there are two modules containing different entities but with the same name. The qualified import allows you to prefix the imported names with the imported module. Consequently, I am not sure if you need a qualified import in your example at all.

In summary you should make the following changes:

  • Rename the file containing the Shapes module to "Shapes.hs"
  • Rename your second file from "surfaceImport.hs" to something like "ShapesUsageExample.hs"
  • Change your import to import Shapes
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.