Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependent Types in Elm

I'm wondering if it's possible to do some sort of dependent typing like the following in Elm, like you can in Idris:

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

Is there a library that will let me achieve a similar effect via typing?

like image 384
Tristan Greeno Avatar asked Feb 04 '23 15:02

Tristan Greeno


1 Answers

You could do something alike with union types.

type Sentence 
    = Question String
    | Statement String

isQuestion : String -> Sentence
isQuestion sentence =
    case endsWith "?" sentence of
        True -> Question sentence
        False -> Statement sentence
like image 187
farmio Avatar answered Feb 12 '23 20:02

farmio