Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display function types in Haskell

Tags:

types

haskell

Other than loading a Haskell file into GHCi and then using :type <expr>, is there any way to have the compiler display types for all of the functions as they are compiled?

like image 344
Ralph Avatar asked Jun 06 '13 20:06

Ralph


People also ask

What are function types in Haskell?

Functions can also be passed as arguments or returned (as we have seen). Their types are given in the type signature. *Main> :t map map :: (a -> b) -> [a] -> [b] *Main> :t filter filter :: (a -> Bool) -> [a] -> [a] flip_args :: (a -> b -> c) -> b -> a -> c flip_args f x y = f y x.

How do I print a type in Haskell?

a. to just print it during compilation, you could enable PartialSignatures extension, and add to arbitrary expression signature :: _ , then its type will be printed during compilation. b. to actually get the type as a data for runtime handling, you could use TemplateHaskell extension and function reify from it.

How do you find type in Haskell?

If you need to figure out what the type of an object is in a Haskell program, I hope this is helpful. Note that if you are in GHCI, you can just put :type before your expression to determine the expression's type, or use :set +t to see the type of every expression in GHCI.

How does show function work in Haskell?

The shows functions return a function that prepends the output String to an existing String . This allows constant-time concatenation of results using function composition.


1 Answers

If you pass -fwarn-missing-signatures (or -Wall) to GHC it will list every top-level function that has no type annotation in the file, together with the inferred type.

like image 53
Joachim Breitner Avatar answered Oct 04 '22 20:10

Joachim Breitner