简体   繁体   English

Haskell没有类型同义词的数据构造函数

[英]Haskell no data constructors for type synonym

I've defined a haskell data type with constructors and a type synonym for it.I'm not able to use its data constructors. 我已经定义了带有构造函数的haskell数据类型和它的类型同义词。我无法使用其数据构造函数。

Type definition : 类型定义:

module BinaryTreeModule(BinaryTree,..) where
data BinaryTree a = Empty | Node (BinaryTree a) a (BinaryTree a)

type synonym: 类型同义词:

import BinaryTreeModule(BinaryTree)
type BST = BinaryTree

usage: 用法:

insert :: a -> BST a -> BST a
insert _ Empty = ...
insert _ Node .. = ...

I'm getting an error saying Empty and Node constructors not found. 我收到一条错误消息,指出没有Empty和Node构造函数。

I've also defined them in different files. 我还在不同的文件中定义了它们。 If BST is just a synonym for BinaryTree shouldn't their constructors be the same ? 如果BST只是BinaryTree的同义词,它们的构造函数不应该相同吗?

Also is there a better way to "inherit" the BinaryTree type to different types? 还有没有更好的办法将BinaryTree类型“继承”为其他类型? Are typeclasses the correct solution here? 类型类是正确的解决方案吗?

Edit: added how I'm importing between files 编辑:添加了我如何在文件之间导入

After @Carsten's comment, I realised I'm not importing the constructors from the module @Carsten发表评论后,我意识到我没有从模块中导入构造函数

import BinaryTreeModule(BinaryTree(Empty,Node)) fixed the issue import BinaryTreeModule(BinaryTree(Empty,Node))解决了该问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM