0

When I try this in Idris,

contrived : (List a, Char, (Int, Double), String, Bool) -> Bool
contrived   ([]    ,  'b',  (1,   2.0),   "hi" , True) = False
contrived    (a,  b,  c,   d,  e) = True

I receive the error message Can't infer argument a to contrived, Can't infer argument a to List, Can't infer argument a to []. But looking at the Manning book, I don't see any obvious syntactic issues with my approach.

bbarker
  • 11,636
  • 9
  • 38
  • 62

1 Answers1

4

you receive the error message, since Idris would like to now what the type a (or rather [] is when you invoke the function in the REPL. You can specifiy this implicit information like so:

contrived {a = Nat} ([],  'b',  (1, 2.0), "hi" , True)
> False

Or like this:

contrived (the (List Nat) [],  'b',  (1, 2.0), "hi" , True)
> False

In a true program that would not be required:

EmptyList: List Nat
EmptyList = []

testCase: contrived (EmptyList, 'b', (1, 2.0), "hi", True) = False
testCase = Refl
Markus
  • 1,293
  • 9
  • 10
  • Thanks - sorry for the delayed follow up - 1) what is `the` syntax known as in Idris? and 2) what is meant by a `true` program, and last but not least: 3) is there any way to match on an empty list `[]` without specifying its type parameter `a` in Idris, like in Haskell or Scala? – bbarker Jun 01 '18 at 00:21
  • 1
    @bbarker `the` is an ordinary function to manually assign a type to a value. See `:doc the` By true program I meant one, you write and execute in idris, and not the REPL. In these kind of programs types are generally known unlike in the REPL. I do not know what the 3rd question is. You successfully did that. Only when invoking the function idris complains. That would be the same in scala. You cannot construct a List with unknown type. In scala the compiler will sometime try to infer a type, but not in idris. – Markus Jun 01 '18 at 06:10