Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Improved) refinement types #16

Open
rockofox opened this issue Dec 9, 2024 · 0 comments
Open

(Improved) refinement types #16

rockofox opened this issue Dec 9, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@rockofox
Copy link
Owner

rockofox commented Dec 9, 2024

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
@rockofox rockofox added the enhancement New feature or request label Dec 9, 2024
@rockofox rockofox modified the milestone: Decent Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant