is there a way to include constraints / required certain iplemented abilities when defining the types required by a platform
Hi @Nathan Kamenchu,
Can you be more specific here: "when defining the types required by a platform"
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.
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
Is it possible to expose a function from the platform that as one of the required types as an argument?
Yes, I think that should work. Note that they are not truly required types but identifiers with a specific type (usually functions).
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!]
these modules cannot import from the main.roc file
Yes, I think that's correct
Last updated: Jul 05 2025 at 12:14 UTC