我想知道是否有可能在Elm中进行某种依赖类型,如下所示:
isQuestion : String -> Type
isQuestion (sentence) with (endsWith "?" sentence)
| True = Question
| False = Statement
是否有一个库可以让我通过打字实现类似的效果?
答案 0 :(得分:6)
你可以用联合类型做同样的事情。
type Sentence
= Question String
| Statement String
isQuestion : String -> Sentence
isQuestion sentence =
case endsWith "?" sentence of
True -> Question sentence
False -> Statement sentence