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

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?

1 Like

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?

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

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.

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

2 Likes