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
相關文章
- Migrate database from single instance to Oracle RACDatabaseOracle
- npm publish gives “unscoped packages cannot be private”NPMPackage
- ORA-15055 ASM Diskgroup Status Showing Dismounted From RDBMS InstanceASM
- OpenAPI definition(示例)API
- Monad和Monoid的定義Mono
- SAP Spartacus Definition of Done
- Definition of ad hoc query
- Simple definition of SAP productions
- 《Haskell趣學指南》筆記之 MonoidHaskell筆記Mono
- Haskell Monoid(么半群)的介紹HaskellMono
- 類定義(class definition)
- Typescript basicTypeScript
- WPF implemented Single Instance via mutex and activated the existed window via FindWindow from Microsoft.Win32; namespaceMutexROSWin32namespace
- not found service definition in jdonframework.xmlFrameworkXML
- Golden Gate的definition檔案Go
- V$sort_usage, where is the definition?
- R12 help--diagnostics--examine gives function not available errorFunctionAIError
- ASMCA fails to create 11.2 ASM instance when upgrading from 10.2 [ID 1125053.1]ASMAI
- OpenAPI Basic StructureAPIStruct
- Docker-BasicDocker
- JUnit basic annotation
- MySQL - DDL詳解(Data Definition Language)MySql
- typedef and struct inside class definition?StructIDE
- Codeforces 897C Nephren gives a riddle:模擬【珂學】
- IPFS_basic_use
- numpy_torch_basic
- HS: Created new FDS class definition in server DDServer
- Machine Learning - Basic pointsMac
- Visual Basic for ApplicationAPP
- Spark Basic RDD 操作示例Spark
- Postgres Basic Commands for Beginners
- [Vue] Slots - 1. basicVue
- Qt報Multiple definition錯誤的解決QT
- Audio device on High definition Audio busdev
- zero-shot-learning-definition-examples-comparison
- instance和clientclient
- Oracle database instanceOracleDatabase
- The Instance and the Database (285)Database