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

Function usage question to have specific field based on arugment. #1308

Open
buzzerpuzzle opened this issue Oct 6, 2022 · 0 comments
Open

Comments

@buzzerpuzzle
Copy link

buzzerpuzzle commented Oct 6, 2022

Hi team!

I'm thinking about whether I could use parameter to determine whether to have specific field.

Base on my last question, I could pass test argument to determine whether to have b field.

testFunction.dhall
let testFunction = \(args : { test : Bool }) ->
  { a = "123", b = if args.test then Some "test" else None Text }
in testFunction

I would like to make it to be more flexible more than just text but got the issue with mismatch field error.
Hope you guys could give me more context how to make it work.

a.dhall

let a = {
    version = "123",
    description = "456"
} in a

b.dhall

let testFunction = \(args : { test : Bool }) ->
  { a = "123", b = if args.test then ./a.dhall else None Text }
in testFunction

Error message

dhall-to-yaml-ng <<< './b.dhall {test=True}'


↳ ./b.dhall

Error: ❰if❱ branches must have matching types

- None
+ Optional
…

2│                    if args.test then ./a.dhall else None Text

/Users/Projects/learning-dhall/b.dhall:2:20

1│ ./b.dhall

(input):1:1

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant