榆树中的依赖类型

时间:2017-04-19 20:37:17

标签: types elm dependent-type idris

我想知道是否有可能在Elm中进行某种依赖类型,如下所示:

isQuestion : String -> Type
isQuestion (sentence) with (endsWith "?" sentence)
    | True = Question
    | False = Statement

是否有一个库可以让我通过打字实现类似的效果?

1 个答案:

答案 0 :(得分:6)

你可以用联合类型做同样的事情。

type Sentence 
    = Question String
    | Statement String

isQuestion : String -> Sentence
isQuestion sentence =
    case endsWith "?" sentence of
        True -> Question sentence
        False -> Statement sentence