Skip to content

(Improved) refinement types #16

Description

@kilofox
struct Person = (age: Int)
let can_drink (it: Person) => Bool = it.age > 21

let drink (person: Person{can_drink} beverage: String) => IO = ...

let main => IO = do
	drink Person {age: 23} # Fine
	drink Person {age: 16} # Error: 16 fails refinement `can_drink`
	
	println "How old are you?"
	let age = ($getLine) as Int
	drink Person{age: age} # Error: cannot validate refinement `can_drink`


	assert (can_drink person) do
		drink person
	else
		println "Under drinking age!"
	end
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions