你好,我想知道你如何解决Haskell中的循环依赖
我有:
类型的模块。
module Company where
import Tclass
data Worker=Worker{
age::Int,
name::String,
title::Title,
income::Int
}
data Title=Manager | Dev | Tester deriving (Show)
data Company=Company{
cname::String,
people::[Worker],
yf::Int
}
类型类实例的模块
module Tclass where
import System.Environment
import Company
class Console a where
wLine::a->IO()
rLine::IO String->a
instance Show Worker where
show w="to be defined"
print =putStr . show
如果我只想在ghci中加载类型并使用它;如何导入它们而不会出现错误:
Module imports form a cycle:
module `Tclass' (.\Tclass.hs)
imports `Company' (Company.hs)
which imports `Tclass' (.\Tclass.hs)
PS 我尝试创建一个辅助模块来导入两个模块,而这两个模块也可以导入它,但是这两个模块也没有运气:
module Au where
import Tclass
import Company
module Company
import Au
module Tclass
import Au
答案 0 :(得分:3)
将Show实例移至其他模块,可以中断周期:
module Tclass where
import System.Environment
import Company
class Console a where
wLine::a->IO()
rLine::IO String->a
和
module Company where
data Worker=Worker{
age::Int,
name::String,
title::Title,
income::Int
}
instance Show Worker where
show w="to be defined"
print =putStr . show
data Title=Manager | Dev | Tester deriving (Show)
data Company=Company{
cname::String,
people::[Worker],
yf::Int
}