#lang plait (define-type Story (happy [text : String]) (sad [text : String]) (choice [text : String] [l : Story] [r : Story])) ;; Example Storys (sad "The end") (happy "They lived happily ever after") (choice "Take programming languages?" (happy "They lived happily ever after") (sad "The end")) (define (has-happy? [s : Story]) : Boolean (type-case Story s [(happy t) #t] [(sad t) #f] [(choice t l r) (or(has-happy? l)(has-happy? r))])) (test (has-happy? (choice "Take programming languages?" (happy "They lived happily ever after") (sad "The end"))) #t) (test (has-happy? (choice "Take programming languages?" (sad "They didn't live happily ever after") (sad "The end"))) #f)