在类型级别未定义
通常,当我使用 Haskell 代码时,我会使用类型注释和 undefined
来存根。
foo :: String -> Int
foo = undefined
是否有一个类型级别的“未定义”,我可以以类似的方式使用?
(理想情况下,与某种注释结合使用)
type Foo :: * -> *
type Foo = Undefined
对同一线程的进一步思考:有没有办法让我为以这种方式创建的类型存根类型类实例?比以下理论方法更简单的方法?
instance Monad Foo where
return = undefined
(>>=) = undefined
Often when I'm playing with Haskell code, I stub things out with a type annotation and undefined
.
foo :: String -> Int
foo = undefined
Is there a type-level "undefined" that I could use in a similar way?
(Ideally, in conjunction with a kind annotation)
type Foo :: * -> *
type Foo = Undefined
Further thought on the same thread: is there a way for me to stub out typeclass instances for types created this way? An even easier way than the following theoretical way?
instance Monad Foo where
return = undefined
(>>=) = undefined
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
EmptyDataDecls
来存根类型,并且使用KindSignatures
您可以给它一个类型:您还可以存根
Monad
实例,而无需使用此选项向 GHC 发出警告。然后您不需要为
return
和>>=
保留任何实现。You can use
EmptyDataDecls
to stub out a type, and withKindSignatures
you can give it a kind:You can also stub out the
Monad
instance without warnings with this option to GHC.And then you don't need to leave any implementation for
return
and>>=
.这个问题很久以前就被问过并回答过;此后,最佳实践不断发展。
如今,为了删除代码,您应该使用 类型化洞,以及它们的类型级类似物,部分类型签名 。
This question was asked and answered a long time ago; best practices have evolved since.
These days, instead of
undefined
, for stubbing out code you should be using typed holes, and their type-level analogue, partial type signatures.