无法声明受 Monad 约束的 MonadPlus 接口

编程入门 行业动态 更新时间:2024-10-11 17:19:32
本文介绍了无法声明受 Monad 约束的 MonadPlus 接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试像这样声明 MonadPlus 接口:

I'm trying to declare MonadPlus interface like that:

module NanoParsec.Plus %access public export interface Monad m => MonadPlus m where zero : m a plus : m a -> m a -> m a

但是有一个错误:

| 5 | interface Monad m => MonadPlus m where | ~~~~~~~ When checking type of constructor of NanoParsec.Plus.MonadPlus#Monad m: When checking argument m to type constructor Prelude.Monad.Monad: Type mismatch between Type (Type of m) and Type -> Type (Expected type)

我做错了什么?如何解决这个问题?Idris 没有自己的 MonadPlus 接口是对的吗?如果是,为什么?

What I'm doing wrong? How to fix this? Am I right that Idris has no its own MonadPlus interface? If so, why?

推荐答案

在Idris中,当你定义一个接口时,参数类型默认为Type,所以MonadPlus m这里是 MonadPlus (m: Type) 的缩写,Idris 将 m 视为 Type.这当然不符合约束 Monad m,它需要 Type ->输入.

In Idris, when you define an interface, the parameter type defaults to Type, so MonadPlus m here is short for MonadPlus (m: Type), and Idris treats m as a Type. This of course doesn't fit with the constraint Monad m, which expects a Type -> Type.

如果你想参数化其他东西,你必须明确,比如

You have to be explicit if you want to parametrize over something else, like

interface Monad m => MonadPlus (m: Type -> Type) where zero : m a plus : m a -> m a -> m a

MonadPlus 本身超出了我的知识范围,所以我不知道它在 Idris 中是否存在.

MonadPlus itself is beyond my knowledge so I don't know about its presence, or lack thereof, in Idris.

更多推荐

无法声明受 Monad 约束的 MonadPlus 接口

本文发布于:2023-11-29 11:42:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646298.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:接口   声明   Monad   MonadPlus

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!