Skip to content
Discussions/App Development/Is there a way to display the "type" of a function or data type in Daml?Forum ↗

Is there a way to display the "type" of a function or data type in Daml?

App Development5 posts251 views3 likesLast activity Jan 2022
ME
meetOP
Jan 2022

Is there a way to display the “type” of a function or data type in Daml - equivalent to typeof in JavaScript or :t functionName in Haskell?

ST
stefanobaghino-da
Jan 2022

typeof in JS and :t in Haskell are quite different. Do you mean in Daml Studio, in the REPL, or as some form of runtime reflection?

ME
meet
Jan 2022

In Daml Studio, one can already see the type by hovering over the function or data type.
I’m looking to know if there’s a way to do it in:

  1. REPL
  2. runtime reflection
LU
Luciano
Jan 2022

Yes, kind of …

In the repl, you can use holes, as you would in a source file, like so:

daml> import DA.Assert ((===))
daml> foldl _ _ ["Hello", "world", "!"] === [(0, "Hello"), (1, "world"), (2, "!")]
File:     <string>
Hidden:   no
Range:    1:7-1:8
Source:   typecheck
Severity: DsError
Message: 
  <string>:1:7: error:
  • Found hole: _ : [(Int, Text)] -> Text -> [(Int, Text)]
  • In the first argument of ‘foldl’, namely ‘_’
  In the first argument of ‘(===)’, namely
  ‘foldl _ _ ["Hello", "world", "!"]’
  In the first argument of ‘show’, namely
  ‘(foldl _ _ ["Hello", "world", "!"]
  === [(0, "Hello"), (1, "world"), (2, "!")])’

So you can see in the error message, it tells you the type (after “Found hole”).
It won’t work in every case, but for functions it does the job.

CO
cocreature
Jan 2022

And just to make this explicit, there is no runtime reflection of types.

← Back to Discussions