在类型级别未定义 [英] Undefined at the type level

查看:147
本文介绍了在类型级别未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常当我使用Haskell代码时,我会用类型注释来存储,而 undefined

Often when I'm playing with Haskell code, I stub things out with a type annotation and undefined.

foo :: String -> Int
foo = undefined

是否有可以使用的类型级别undefined以类似的方式吗?

Is there a type-level "undefined" that I could use in a similar way?

(理想情况下,结合一种注释)

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


推荐答案

可以使用 EmptyDataDecls 存根出一个类型,并与 KindSignatures 你可以给它一种:

You can use EmptyDataDecls to stub out a type, and with KindSignatures you can give it a kind:

{-# LANGUAGE EmptyDataDecls, KindSignatures #-}

data Foo :: * -> *

您也可以将 Monad 没有警告的实例使用GHC的这个选项。

You can also stub out the Monad instance without warnings with this option to GHC.

{-# OPTIONS_GHC -fno-warn-missing-methods #-}

instance Monad Foo

然后您不需要任何实现 return >> =

And then you don't need to leave any implementation for return and >>=.

这篇关于在类型级别未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆