Comments (5)
Hi Chris! This is a really good question. I'm glad to see that others have run into this weird corner of the language design as well. It presented a bunch of problems throughout the design and implementation of tower.
Unfortunately, we haven't come up with a satisfactory solution for every use case. We have, in the past, solved this problem by relying on a call
on an ivory function is strict only on the function identifier (string argument to proc).
So to re-use your example program
foo :: Bar -> Def ('[] :-> ())
foo bar = procImpl "some_constant_string" $ body $ do ...
The caller of foo
, who may not have a bar
argument available, can still generate valid code via call_ (foo undefined)
or better yet call_ (foo (error "broken invariant: call to foo should not be strict in the argument"))
. So you can export some variant of foo
from the module that gives a proper error message, and have some other way internally to apply the correct Bar
where foo is incl
ed, which is strict in that argument.
Admittedly, this is ugly, because abusing strictness often makes code hard to read and reason about. But if you do so in a a principled way, perhaps you could implement your proposed procDecl
and procImpl
along these same lines as a library, rather than a modification to ivory
, if you were willing to wrap (or replace) Def
with another dataype (perhaps ProtoDef
?), and make variants of of call
and incl
that do the correct thing.
As far as extending the Ivory language to include this concept, I don't have any specific objections to your proposal, but I'd defer to @elliottt and others to think on it further. While I totally understand the ways this is useful (and, in terms of C programming, even idiomatic) I'm a bit wary to add anything more to the language that can be implemented as a library.
from ivory.
Pat, good to see I'm not alone in having this problem! By coincidence, I also ran into http://okmij.org/ftp/Haskell/tr-15-04.pdf and saw that my issue is probably 90% just a more specific form of the 'configurations problem'.
It looks like a library should be able to accomplish this. I can't see any reason why the AST needs some special representation of a function prototype.
I hadn't thought of relying on call
being strict only on the name. Still, though, it seems like DefImport
(as importProc
creates) is a cleaner/safer representation, since one may examine the Def
and just treat it like a procedure defined elsewhere, while DefProc
adds a procBody
field that must remain unevaluated.
That suggests one way - creating a function to turn a DefProc
to a DefImport
(and leaving body untouched), and extending this to handle functions of arbitrary arity that produce a Def
by applying however many error ...
.
from ivory.
Sounds good! I'll close this issue, but please re-open it if you discover any issues while implementing your library functionality.
from ivory.
@Hodapp87, why can't the issue be resolved as follows to elide the configuration parameter from the constant being call
ed (fooProxy
) while ensuring that the type of fooProxy
must be consistent with the type of foo
, with the configuration parameter?
data Bar = Bar { aField :: Int }
defaultBar :: Bar
defaultBar = Bar 0
foo :: Bar -> Def ('[Uint8] :-> ())
foo bar = proc "foo_proc" $ \_x -> body $ do retVoid
fooProxy :: Def ('[Uint8] :-> ())
fooProxy = foo defaultBar
caller :: Def ('[] :-> ())
caller = proc "caller" $ body $ call_ fooProxy 3
from ivory.
@leepike, the way I see it, this just becomes the same thing if it's generalized to support arbitrary types. I will show you what I mean with a pull request once I've converted over what I did a few days ago and put it someplace appropriate in Ivory.
from ivory.
Related Issues (20)
- Invalid code generated: initialization discards βconstβ qualifier from pointer target type HOT 9
- Hackage build failed HOT 4
- The documentation for the latest version of this package is missing on Hackage. HOT 2
- Question: Using "Simple" Sum Types in Ivory HOT 2
- Why `deref` is effectful? HOT 7
- Add support for template-haskell-2.12 HOT 1
- Constant assertions
- Remove `IvoryZero` constraint from `ifte` and `cond`
- Travis entry for 7.10 looks invalid
- http://ivorylang.org seems down HOT 1
- How to actually run the tutorial? HOT 1
- ivory-backend-acl2 can not work
- Incompatibility with newer versions of base-compat and monadLib HOT 1
- The documentation for the latest version of `ivory-backend-c` is missing on Hackage. HOT 3
- ProcPtrs and Refs in MemAreas
- Remove noop casts in the C code HOT 4
- Finish/integrate new model-checker
- Generalize Ivory memory model
- Ivory module system improvements
- cvc4 errors in local test HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ivory.