Sono un principiante in Haskell. Ecco alcune semplici righe di codice:Perché ghci può vedere tipi e costruttori non esportati? Come posso ripararlo?
module Src
( -- The 'Answer' type isn't exported
Shape(Circle), -- i.e 'Rectangle' data constructor isn't exported
Point(..),
area,
nudge
) where
data Answer = Yes | No deriving (Show)
data Point = Point Float Float deriving (Show)
data Shape = Circle Point Float | Rectangle Point Point
deriving (Show)
area :: Shape -> Float
area (Circle _ r) = pi * r^2
area (Rectangle (Point x1 y1) (Point x2 y2)) = (abs $ x2 - x1) * (abs $ y2 - y1)
nudge::Shape->Float->Float->Shape
nudge (Rectangle(Point x1 y1)(Point x2 y2)) dx dy = Rectangle
(Point (x1 + dx) (y1 + dy)) (Point (x2 + dx) (y2 + dy))
nudge (Circle (Point x y) r) dx dy = Circle (Point(x + dx) (y + dy)) r
ho nascosto il tipo Answer
e il costruttore Rectangle
. Ma quando carico il Src.hs di file, ghci li vede ancora:
ghci> :l src
[1 of 1] Compiling Src (src.hs, interpreted)
Ok, modules loaded: Src.
ghci> let a = Yes
ghci> a
Yes
ghci> :t a
a :: Answer
ghci> let r = Rectangle (Point 0 0) (Point 100 100)
ghci> r
Rectangle (Point 0.0 0.0) (Point 100.0 100.0)
ghci> :t r
r :: Shape
ghci>
Perché questo è accaduto e come posso risolvere il problema?
You' Hai cose nascoste da cose che importano il modulo, ma non puoi nascondere un file da solo! –