Dhall - Expression doesn't match annotation, type Text expected

387 Views Asked by At

I'm working with Dhall 1.39.0 and getting this error:

Error: Expression doesn't match annotation

- Text
+ { … : … } (a record type)
[snip]

You or the interpreter annotated this expression:

[ file contents ] 

... with this type or kind:

↳ Text

... but the inferred type or kind of the expression is actually:

↳ { Sentences :
      List
        { Name : Text
        , Object : Text
        , Statement : Bool
        , Subject : Text
        , Verb : Text
        }
  , Version : Text
  }



This is yielded from cat show-and-tell.dhall | ~/external-programs/bin/dhall --explain text.

Note that I can load the relevant dhall file into the dhall-golang library and have it rendered correctly. So I'm quite a bit confused.

A somewhat contrived sample file is here:


let Sentence : Type  =
{
  Name : Text,
  Subject : Text ,
  Verb : Text ,
  Object : Text ,
  Statement : Bool
}
let Information : Type = {
  Version : Text,
  Sentences : List Sentence
}


let all = ".+"

let answer : Information =  {
    Version = "v1"
    , Sentences =
    [ { Name = "s1"
    , Subject = "bobross"
    , Verb = "${all}"
    , Object = "${all}"
    , Statement = True
    }
    , { Name = "s2"
    , Subject = "Everyone"
    , Verb = "${all}"
    , Object = "${all}"
    , Statement = False
    }
    , { Name = "s3"
    , Subject = "picasso"
    , Verb = "questions"
    , Object = "${all}"
    , Statement = True
    }
  ]
}
in answer
1

There are 1 best solutions below

0
On BEST ANSWER

dhall text is for rendering the value of a Dhall expression of type Text (somewhat like, e.g., the -r option to jq):

$ echo '"Foo"' | dhall text
Foo

as compared to

$ echo '"Foo"' | dhall
"Foo"

Your expression has type Information; you just need dhall by itself.

$ cat show-and-tell.dhall | dhall
{ Sentences =
  [ { Name = "s1"
    , Object = ".+"
    , Statement = True
    , Subject = "bobross"
    , Verb = ".+"
    }
  , { Name = "s2"
    , Object = ".+"
    , Statement = False
    , Subject = "Everyone"
    , Verb = ".+"
    }
  , { Name = "s3"
    , Object = ".+"
    , Statement = True
    , Subject = "picasso"
    , Verb = "questions"
    }
  ]
, Version = "v1"
}