Skip to content

feat: support import values from file: URI scheme #4935

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

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft

Conversation

ggreif
Copy link
Contributor

@ggreif ggreif commented Mar 5, 2025

I am suggesting importing amorphous files using the file: URI scheme:

import (blobby : Blob) = "file:Bla.wasm";
import (texty : Text) = "file:Bla.md";
import (principally : Principal) = "file:Bla.txt";

Leaving the type away would default to Blob.

To develop this idea further, import (friends : [{ name : Text; birthday : Text; ...}]) = "file:friends.csv" would be in reach. But I am sceptical of the utility (for other than test data generation).

Eventually resolves #4934.


This is super early, I am butchering basically everything, such as

  • type checker (T.Pre at bad phases)
  • compilation units (there should be a ValueU)
  • it should be file://
  • use check_text

@@ -0,0 +1 @@
file-import.mo:1.9-1.10: warning [M0194], unused identifier f (delete or rename to wildcard `_` or `_f`)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be a type error

@crusso
Copy link
Contributor

crusso commented Mar 13, 2025

I think it might be easier to have differnt uris

impor bloby = "blob:Bla.wasm";
import texty = "text:Bla.md";
import principally = "principal:Bla.txt";
import envvar= "env:USER";
import foreignclass= "class:foo.wasm";

@ggreif ggreif self-assigned this Mar 14, 2025
@ggreif ggreif added the feature New feature or request label Apr 1, 2025
ggreif added 9 commits April 4, 2025 17:55
- we'll need `ValueU` (now using ad-hoc `ProgU`)
- need to actually open/read the file
- so far we have
  ``` Motoko
  import (f : Blob) = "file:CI.md";
  > let f : Blob = "blobbyblob"
  import (f : Text) = "file:CI.md";
  > let f : Text = "blobbyblob"
  ```
just checked, this always worked:
``` Motoko
import (f : {sin : Float -> Float}) = "mo:prim";
> let f : {sin : Float -> Float} = {sin = <func>}
```
with `Blob` default type

this still allows
``` Motoko
import (f : Nat) = "file:CI.md";
```
but now
``` Motoko
import f = "file:CI.md";
```
also becomes possible!
```
(LetD (VarP file$../index.html) (PrimE TupPrim))
(LetD (VarP t) (LitE (TextLit ../index.html)))
(LetD (VarP b) (LitE (BlobLit "../index.html")))
(LetD (VarP b0) (LitE (BlobLit "../index.html")))
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support including Blobs from the file system during build
2 participants