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

add option types to encore #223

Merged
merged 2 commits into from
Sep 25, 2015
Merged

Conversation

kikofernandez
Copy link
Contributor

addition of option types to encore. there is a type constructor called Maybe t
which represent the option type. valid data constructors for option
types are Just t and Nothing. there are some examples in the file
maybeType.enc. a small example would be:

def test_catch_all(z: Maybe int): string
  match z with
  z => "catchall"
  Just 32 => "Error, general condition should have been catched
  first"

this is translated to c into a bunch of if-else statements. i mean a
bunch because the developer can match on nested option types of the form
Maybe (Maybe int).

restrictions:

  • there is not match all clause in the match expression

@EliasC
Copy link
Contributor

EliasC commented Sep 24, 2015

All my previous issues have been resolved, but I stumbled upon a weird thing:

def foo() : ()
  match Just 42 with
    42 => ()

This program throws the compiler into an infinite loop somewhere in the typechecker (use the -voption to see how far compilation gets). Upon further inspection it seems like this happens when you put anything that isn't a variable access or of Maybe type as a pattern (I discovered this when I used a type cast). When this is fixed I think this PR is ready to be merged!

tuplecheck parentType (x, y) = do
x' <- typecheck x
y' <- typecheck y
tuplecheck parentType (x', y')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case looks suspicious (re: infinite loop)

Kiko Fernandez Reyes added 2 commits September 24, 2015 19:15
addition of option types to encore. there is a type constructor called `Maybe t`
which represent the option type. valid data constructors for option
types are `Just t` and `Nothing`. there are some examples in the file
`maybeType.enc`. a small example would be:

    def test_catch_all(z: Maybe int): string
      match z with
      z => "catchall"
      Just 32 => "Error, general condition should have been catched
      first"

this is translated to c into a bunch of if-else statements. i mean a
bunch because the developer can match on nested option types of the form
`Maybe (Maybe int)`.

restrictions:
  - there is not match all clause in the `match` expression
fix typechecking an expression which is not an option type or a var access
EliasC added a commit that referenced this pull request Sep 25, 2015
@EliasC EliasC merged commit 5b4278a into parapluu:master Sep 25, 2015
@albertnetymk
Copy link
Contributor

While we are on this, why is word preliminary used, instead of dependency?

@kikofernandez
Copy link
Contributor Author

@albertnetymk I think you are in the wrong PR?

@kikofernandez kikofernandez deleted the features/maybe-type branch September 25, 2015 07:24
@albertnetymk
Copy link
Contributor

Sorry, wrong tab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants