A basic Monoid definition gives “No instance for (Semigroup MyMonoid) arising from the superclasses
在定義一個自己的Monoid時haskell報了錯誤:
module MyMonoid where
import qualified Data.IntSet as S
data MyMonoid = MyMonoid S.IntSet
instance Monoid MyMonoid where
mempty = MyMonoid S.empty
MyMonoid m1 `mappend` MyMonoid m2 = MyMonoid (S.union m1 m2)
報錯:
• No instance for (Semigroup Markup)
arising from the superclasses of an instance declaration
• In the instance declaration for ‘Monoid MyMonoid’
解決方法:
(<>)
已從Monoid移到Semigroup,並且所有Monoid例項也必須也是Semigroup。mappend
只是的同義詞(<>)
。因此,需要兩個例項:
instance Semigroup MyMonoid where
MyMonoid m1 <> MyMonoid m2 = MyMonoid (S.union m1 m2)
instance Monoid MyMonoid where
mempty = MyMonoid S.empty
相關文章
- WPF implemented Single Instance via mutex and activated the existed window via FindWindow from Microsoft.Win32; namespaceMutexROSWin32namespace
- npm publish gives “unscoped packages cannot be private”NPMPackage
- OpenAPI definition(示例)API
- SAP Spartacus Definition of Done
- vertx instance
- GPU InstanceGPU
- 《Haskell趣學指南》筆記之 MonoidHaskell筆記Mono
- Haskell Monoid(么半群)的介紹HaskellMono
- 類定義(class definition)
- typedef and struct inside class definition?StructIDE
- Typescript basicTypeScript
- Basic Paxos
- 3.2.1 Mounting a Database to an InstanceDatabase
- 3.1.5.6 Forcing an Instance to Start
- OpenAPI Basic StructureAPIStruct
- Visual Basic for ApplicationAPP
- zero-shot-learning-definition-examples-comparison
- MySQL - DDL詳解(Data Definition Language)MySql
- C++ instance的使用C++
- RMAN Duplicate RAC to Single Instance
- Recommendation Systems Basic Notes
- Reinforcement Learning Basic Notes
- Machine Learning - Basic pointsMac
- numpy_torch_basic
- IPFS_basic_use
- 3.1.5.2 Starting an Instance, and Mounting and Opening a DatabaseDatabase
- Property [title] does not exist on this collection instance
- Qt報Multiple definition錯誤的解決QT
- Basic Authorization 認證方法
- [Vue Form] Basic Select componentVueORM
- [Vue] Slots - 1. basicVue
- AWS-Basic-S3S3
- From now on
- axios如何傳送Basic AuthiOS
- HTTP認證模式:Basic & DigestHTTP模式
- 【Basic Abstract Algebra】Exercises of Section 1.1
- 【Basic Abstract Algebra】Exercises for Section 1.2
- 【Basic Abstract Algebra】Exercises for Section 1.4