Failed to declare MonadPlus interface constrained on Monad

落花浮王杯 提交于 2021-01-04 07:44:27

问题


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

But have an error:

  |
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)

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


回答1:


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 itself is beyond my knowledge so I don't know about its presence, or lack thereof, in Idris.



来源:https://stackoverflow.com/questions/63206752/failed-to-declare-monadplus-interface-constrained-on-monad

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!