-
Notifications
You must be signed in to change notification settings - Fork 6
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
ad hoc user-defined types #47
Comments
I forgot to mention: One thing to be mindful about with the design of |
We can combine a smart constructor and the type checking function in one:
Let's assume we change Then we can have a type signature like: Note that i changed the location of the colon from the first post in this issue. |
Here's an alternative to Then we can do
|
This way custom data types are stable until the code defining them is changed |
MyInt = let wrapper = \h -> ( \i -> if i < 1 or i > 9
then abort "MyInts must be between 1 and 9 exclusive"
else (h, i)
, \i -> if left i == h
then 0
else "expecting MyInt"
)
in wrapper (# wrapper) |
#71 could unlock some interesting possibilities for this. I'm wondering if |
MyInt = let wrapper = \h -> ( \i -> if not i
then "MyInt must not be 0"
else i
, \i -> if dEqual (left i)
then 0
else "expecting MyInt"
)
in wrapper (# wrapper)
main = \i -> ((right MyInt) 8, 0) This runs without complaining: [hhefesto@olimpo:~/src/telomare]$ cabal run telomare examples.tel
Up to date
done Why? 🧐🤔 |
There isn't any |
What is weirdest for me is that |
Leaving this here for safe keeping (from gitter): sfultong \i : (\i -> assert i "MyInt must not be 0") -> (h, i) the two i lambdas is awkward though, so the design of : probably needs tweaking \i : assert i "MyInt must not be 0" -> (h, i) |
I'm trying to do a small abort with the current syntax. I'm still not too aware of how main : (4,3) 0 = \input -> ("Hello, World!", 0) but that breaks with:
I didn't go any deeper. |
Hmm, I should probably look into why Possible is failing there. That's not exactly how the Look at the refinement section in Spec.hs for better examples |
Thanks! For completeness: -- refinement fail example:2
main : (\x -> if x then "fail" else 0) = 1 fails with: |
how about this syntax: MyInt = let wrapper = \h -> ( \i -> if not i
then abort "MyInt cannot be 0"
else (h, i)
, \i -> if dEqual (left i) h
then 0 -- TODO: Ask sam is this should be 1 instead
else abort "Not a MyInt"
)
in wrapper (# wrapper)
increaseMyInt : (right MyInt) = \ (x : (right MyInt)) -> (left MyInt) (succ (right x))
main = \i -> (increaseMyInt ((left MyInt) 8), 0) n.b. MyInt constructor returns a tuple with the hash and the data of MyInt n.b.2. thoughts? @sfultong |
Yeah, I intended that the |
What is the minimal features we need to add to Telomare to allow for ad hoc user-defined types?
The way I see user-defined types, is that they're nominal typing on top of structural typing. Or rather, they're simply unique labels on top of structure definitions. Since Telomare already is capable of defining arbitrary structures in a sort of untyped way, all we need to add is support of unique labels.
By labels, I really mean natural numbers, since they're isomorphically equivalent.
So, if we add a keyword to Telomare called "unique", then we can define top-level functions:
MyInt = unique
This will assign a unique natural number to MyInt at compile time.
Then we can use this tag later on, in smart constructors:
toMyint = \i -> if i < 1 or i > 9 then abort "MyInts must be between 1 and 9 inclusive" else (MyInt, i)
and check against this tag identifier for "type checking":
incrementMyInt = \i -> let checkedI = if left l == MyInt then right i else abort "incrementMyInt: expecting a MyInt" in toMyInt (succ checkedi)
This is obviously a bit messy and could use more syntatic sugar, but it should demonstrate the basic concept
The text was updated successfully, but these errors were encountered: