Elm 为列表中的类型变量创建条件

Elm 为列表中的类型变量创建条件,elm,Elm,因此,我在列表中列出了一些类型变体: type VariableType = BooleanVariable | ContinuousVariable | CategoricalVariable | Incorrect mylistone = [ContinuousVariable, ContinuousVariable, ContinuousVariable] mylisttwo = [ContinuousVariable, ContinuousVariabl

因此,我在列表中列出了一些类型变体:

type VariableType
    = BooleanVariable
    | ContinuousVariable
    | CategoricalVariable
    | Incorrect

mylistone = [ContinuousVariable, ContinuousVariable, ContinuousVariable]
mylisttwo = [ContinuousVariable, ContinuousVariable, CategoricalVariable]
我需要这样定义一个函数:

listtype : List VariableType -> VariableType
listtype list =
    -- if (List.all isBooleanVariable list) then 
        BooleanVariable
    -- else if (List.all isContinuousVariable list) then 
        ContinuousVariable
    -- else
        CategoricalVariable
因此,上述两个列表的输出应为:

listtype mylistone -- ContinuousVariable
listtype mylisttwo -- CategoricalVariable

但我读到,由于类型擦除,不可能在编译类型之后检查类型。如何定义
isBooleanVariable
isContinuousVariable

BooleanVariable
ContinuousVariable
等。这些都是自定义类型的变体
VariableType
,生成或表示值。因此,您实际上并不是要检查这些类型,它们都有类型
VariableType
,只是它们的值。与任何其他可比值一样,可使用相等运算符进行计算:

listtype:List VariableType->VariableType
列表类型列表=
如果(List.all(\v->v==BooleanVariable)列表),则
布尔变量
否则如果(List.all(==)ContinuousVariable)List)则
连续变量
其他的
可分类变量

明白了,另一个来自SO的回答实际上把我弄糊涂了()。非常感谢。