我正在尝试通过并集运算将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’
我在做什么错?这似乎很简单,我正在复制在this之类的示例中看到的语法,但是我看不到为什么会发生此错误。
答案 0 :(得分:14)
自从编写游览以来,import React from "react";
import ReactDOM from "react-dom";
const Modal = ({ open, toggle }) => {
if (open) {
return (
<React.Fragment>
<h1>Modal</h1>
<button onClick={toggle}>Close</button>
</React.Fragment>
);
}
return null;
};
class App extends React.Component {
state = {
open: false
};
toggle = () => {
this.setState({ open: !this.state.open });
};
render() {
return (
<React.Fragment>
<button onClick={this.toggle}>Open</button>
<Modal open={this.state.open} toggle={this.toggle} />
</React.Fragment>
);
}
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
已从Monoid移到Semigroup,并且所有Monoid实例也必须是Semigroup。 (<>)
只是mappend
的同义词。因此,您需要两个实例:
(<>)