我需要实现动态调度,我已经基于此page使用了Existential类型并产生了以下代码:
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE ExistentialQuantification #-}
module Cqrs.Command where
import Data.UUID
import Data.Time
import Data.Aeson
import Cqrs.Core
import Data.Text
import GHC.Generics
type CommandName = String
class (FromJSON command,ToJSON command , Show command) => Command_ command where
getCommandId :: command -> CommandId
getAggregateId :: command -> AggregateId
getCommandName :: command -> String
data Command = forall command . Command_ command => Command command
getMyCommandName :: Command -> String
getMyCommandName command = getCommandName command
我无法在Command数据类型上使用来自Command_类型类的函数,编译器抱怨这种方式:
/Users/xxx/dev/gsdFlow/src/Cqrs/Command.hs:26:28: error:
• No instance for (Command_ Command)
arising from a use of ‘getCommandName’
• In the expression: getCommandName command
In an equation for ‘getMyCommandName’:
getMyCommandName command = getCommandName command
|
26 | getMyCommandName command = getCommandName command
| ^^^^^^^^^^^^^^^^^^^^^^
答案 0 :(得分:4)
您需要解开@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';
.label{
border-radius: 4px;
font-size: 75%;
padding: 4px 7px;
margin-right: 5px;
font-weight: 400;
color: #fff !important;
}
.mat-paginator-navigation-first {
background: #11c15b;
}
.label-success{
border-radius: 4px;
font-size: 75%;
padding: 4px 7px;
margin-right: 5px;
font-weight: 400;
color: #fff !important;
background: #11c15b;
}
.label-warning{
border-radius: 4px;
font-size: 75%;
padding: 4px 7px;
margin-right: 5px;
font-weight: 400;
color: #fff !important;
background: #e5e500;
}
.label-danger{
border-radius: 4px;
font-size: 75%;
padding: 4px 7px;
margin-right: 5px;
font-weight: 400;
color: #fff !important;
background: #ff5252;
}
.roow {
display: flex;
overflow-x: scroll;
}
.mat-table {
width: 100%;
}
.td-style {
font-family: "Roboto", sans-serif;
font-size: 1.1em;
color: #455a64;
}
.th-style {
font-family: "Roboto", sans-serif;
font-size: 1em;
font-weight: bold;
color: #455a64;
}
.table-title-style {
margin: 20px;
margin-top: 5px;
margin-bottom: 0px;
color: #37474f;
font-weight: 500;
position: relative;
position: sticky;
font-size: 15px;
top: 0;
}
.mat-header-row {
position: sticky;
top: 0;
background-color: #fff;
}
.body {
font-family: Roboto, Arial, sans-serif;
margin: 0;
}
.basic-container {
padding: 30px;
}
.version-info {
font-size: 8pt;
float: right;
}
/** No CSS for this example */
::ng-deep .mat-select-content{
background-color: red;
font-size: 1.5em;
}
table {
width: 100%;
}
构造函数以获取其类型实际上是Command
实例的值。
Command_
FWIW,您为existential antipattern的 strongem 代码编码。为什么不做它
getMyCommandName :: Command -> String
getMyCommandName (Command c) = getCommandName c
完成吗?