views:

77

answers:

2

I have the following code that looks like this

[a,b,c,d] = ["a","b","c","d"]

The compiler reports the warning:

Warning: Definition but no type signature for 'a'
         Inferred type: a :: [Char]

How to silence the warning and specify the type for this expression?

+3  A: 

You can add an explicit type signature for the variables:

a, b, c, d :: String
[a,b,c,d] = ["a","b","c","d"]

There should also be some compiler flag that disables the warning since it's common practice to not explicitly specify the types of every helper variable.

sth
Yes, but I would like to avoid typing a,b,c,d twice.
Dev er dev
You could probably just write [a,b,c,d] = ["a","b","c","d"] :: [String]
mrueg
+2  A: 

No errors in GHCi:

Prelude> let [a,b,c,d] = ["a","b","c","d"]

If you want to give the entire fragment a type, try,

   Prelude> let x :: [String]
                     x@[a,b,c,d] = ["a","b","c","d"]
Don Stewart

related questions