Type declarations for constants

Let's say I have some constants that I want to name:

foo = 1234
bar = 5678
baz = 1337

The default is a type Num a => a, but is it not good practice to explicitly declare types for these constants?

Doing this would be pretty detailed:

foo :: Int
foo = 1234

bar :: Int
bar = 5678

baz :: Int
baz = 1337

You can do it as follows:

foo, bar, baz :: Int
foo = 1234
bar = 5678
baz = 1337

Which works great when there are not many, but when the number of constants increases, you may have to wrap them, and it also seems like you are repeating yourself.

How about this ?:

foo = 1234 :: Int
bar = 5678 :: Int
baz = 1337 :: Int

Would this be considered a good style? What convention?

Update

In fact, it seems that the GHC is not considering the last example with any type declarations at all, as it warns of "top-level binding without type signature".

+3
source share
1

, , . , . , , , ,

foo = 1234 :: Int
bar = 5678 :: Int
baz = 1337 :: Int

GHC , , , . ( .)

, , - , , - . , , "", ( , ) .

+4

All Articles