Stream: platform development

Topic: abilities in platform definitions


view this post on Zulip Nathan Kamenchu (Apr 28 2025 at 09:05):

is there a way to include constraints / required certain iplemented abilities when defining the types required by a platform

view this post on Zulip Anton (Apr 28 2025 at 09:24):

Hi @Nathan Kamenchu,
Can you be more specific here: "when defining the types required by a platform"

view this post on Zulip Brendan Hansknecht (Apr 28 2025 at 16:23):

I don't think you can specify in the header currently, but would need to double check. If you can't specify in the header, you might be able to just use it with the ability and that should add the requirement.

view this post on Zulip Nathan Kamenchu (Apr 29 2025 at 04:30):

I needed a type in the requires section of the platform header to implement a certain ability.
I got around it by providing a function to create an opaque type with the constraint

view this post on Zulip Nathan Kamenchu (Apr 29 2025 at 05:24):

Is it possible to expose a function from the platform that as one of the required types as an argument?

view this post on Zulip Anton (Apr 29 2025 at 08:40):

Yes, I think that should work. Note that they are not truly required types but identifiers with a specific type (usually functions).

view this post on Zulip Nathan Kamenchu (Apr 29 2025 at 18:32):

I think I may not have explained myself fully, I was referring to the part with Model
I went for a different design, but I was investigating if it was possible to expose a function to the application that uses this Model type

It doesn't seem possible because the main.roc file which contains the platform definition and has access to this Model type can only expose modules and not functions to the application built against this platform and as far as I can tell these modules cannot import from the main.roc file

platform "webserver"
    requires { Model } {
        init! : {} => Result Model [Exit I32 Str]_,
        respond! : Http.Request, Model => Result Http.Response [ServerErr Str]_,
    }
    exposes [
        Cmd,
        Dir,
        Env,
        File,
        FileMetadata,
        Http,
        MultipartFormData,
        Path,
        Sqlite,
        Stderr,
        Stdout,
        Tcp,
        Url,
        Utc,
    ]
    packages {}
    imports []
    provides [init_for_host!, respond_for_host!]

view this post on Zulip Anton (Apr 30 2025 at 08:27):

these modules cannot import from the main.roc file

Yes, I think that's correct


Last updated: Jul 05 2025 at 12:14 UTC