Skip to content

Sealed traits #37

@jamesfer

Description

@jamesfer

This is a possible way to implement sealed traits (or the equivalent) without anything more than the module system.

data HiddenBoolean = a
export data True
export data False
export let trueHiddenBoolean = HiddenBoolean True
export let falseHiddenBoolean = HiddenBoolean False
export data Boolean = implicit HiddenBoolean a -> a

Externally, you would use the Boolean data type to require a boolean value of either True or False. The fact that HiddenBoolean is not exported prevents anyone from creating more instances of it.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions