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

do blocks within functions #271

Closed
weaversa opened this issue Mar 9, 2018 · 8 comments
Closed

do blocks within functions #271

weaversa opened this issue Mar 9, 2018 · 8 comments
Labels
type: question Issues that are primarily asking questions wontfix Closed issues that we decided not to fix, but are still potentially relevant

Comments

@weaversa
Copy link
Contributor

weaversa commented Mar 9, 2018

Why does one work and one fail?

sawscript> let f1 a b = (a, b)
sawscript> f1 1 2
(1,2)
sawscript> let f2 a b = do { return (a, b); }
sawscript> f2 1 2

user error (Not a monomorphic type: {a.4} a.4 (Int, Int))
@weaversa weaversa added the type: question Issues that are primarily asking questions label Mar 9, 2018
@TomMD
Copy link
Contributor

TomMD commented Mar 9, 2018

Much like Haskell monads, return isn't simply a way to return from imperative code:

sawscript> :type return
{a.0, a.1} a.1 -> a.0 a.1

If you'd like to remove the ambiguity caused by that first type constructor (a.0 in the above) then you can add a type signature. Notice you can never return foo and get a value of type (Int,Int).

For example:

sawscript> f2 1 2 : TopLevel (Int,Int)
(1,2)

@weaversa
Copy link
Contributor Author

weaversa commented Mar 9, 2018

Are there other monads besides TopLevel?

If not, and there's only one monad, would it be possible to automatically promote (demote?) non-monadic to monadic?

@brianhuffman
Copy link
Contributor

The other monads are the ones for function specs (CrucibleSetup, JavaSetup, etc.) and the ProofScript monad.

It might be useful to have a kind of defaulting to TopLevel, which would help with your example.

@weaversa
Copy link
Contributor Author

weaversa commented Mar 9, 2018

Defaulting would be lovely?

Would that somehow facilitate merging let x and x <- into one thing?

@brianhuffman
Copy link
Contributor

No, defaulting would not let you merge let x and x <-. It would only apply in the (rare) situation where you've written a do block that doesn't use any monadic operations other than return. So the implementation effort would yield a pretty small reward.

Another feature we could consider is to allow the do syntax to be used with non-monadic types, so we could write definitions like

sawscript> let f3 a b = do { let c = b; (a, c); }

@brianhuffman
Copy link
Contributor

Another idea is that maybe we should change the types of most TopLevel operations to have non-monadic types instead, e.g. change a -> TopLevel b to just a -> b.

@brianhuffman
Copy link
Contributor

A third idea is to ditch the monadic types completely in favor of some kind of effect annotations on function types.

@atomb atomb added the wontfix Closed issues that we decided not to fix, but are still potentially relevant label Feb 26, 2021
@atomb
Copy link
Contributor

atomb commented Feb 26, 2021

Using Python to control SAW should provide a more familiar notion of function definitions. That's probably easier than changing SAWScript, so I'm going to close this.

@atomb atomb closed this as completed Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Issues that are primarily asking questions wontfix Closed issues that we decided not to fix, but are still potentially relevant
Projects
None yet
Development

No branches or pull requests

4 participants