Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Showing Types (D?niel Arat?) 2. Re: Showing Types (David McBride) ---------------------------------------------------------------------- Message: 1 Date: Mon, 7 Mar 2016 19:06:03 +0100 From: D?niel Arat? <exitcons...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: [Haskell-beginners] Showing Types Message-ID: <CAHvKd2+oRn29=X9X7pcFjL23oP0Uq8W59c=9vffn1wl8irs...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 How does GHCi show types? Is there a magic function (showType :: a -> String) that does that? Or is this feature buried somewhere deep in the compiler? Can I show, compare and reason about types in a Haskell program? This would be cool: ```haskell test = do let len = sum . map (const 1) when (isInfixOf "Integer" (showType len)) $ putStrLn "restrictive type inferred; maybe try turning off monomorphism restriction" ``` ------------------------------ Message: 2 Date: Mon, 7 Mar 2016 13:27:31 -0500 From: David McBride <toa...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Showing Types Message-ID: <CAN+Tr40xCyNuCEjLNb=yczidpamsbzc64ms0xz221qn9a6d...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" You can use the Data.Typeable module import Data.Typeable :t typeOf True typeOf True :: TypeRep :t show (typeOf True) show (typeOf True) :: String typeOf 1 == typeOf 1 True >typeOf 1 == typeOf True False But it works on concrete types, not functions. Sorry. let len = sum . map (const 1) typeOf len <interactive>:17:1: No instance for (Typeable b0) arising from a use of ?typeOf? In the expression: typeOf len In an equation for ?it?: it = typeOf len On Mon, Mar 7, 2016 at 1:06 PM, D?niel Arat? <exitcons...@gmail.com> wrote: > How does GHCi show types? > > Is there a magic function (showType :: a -> String) that does that? Or > is this feature buried somewhere deep in the compiler? > > Can I show, compare and reason about types in a Haskell program? > > This would be cool: > > ```haskell > test = do > let len = sum . map (const 1) > when (isInfixOf "Integer" (showType len)) $ putStrLn "restrictive type > inferred; maybe try turning off monomorphism restriction" > ``` > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160307/88e39219/attachment-0001.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 93, Issue 7 ****************************************