[Haskell-beginners] How to understand the type "ShowS"?
David McBride
toad3k at gmail.com
Tue Sep 24 15:05:45 CEST 2013
ShowS is just a type alias for String -> String. Anywhere where you could
put a function of type String -> String you could replace that with ShowS.
Examples
blah :: String -> String
blah "abc" = "def"
is no different than
blah :: Shows
blah "abc" = "def"
>From the GHC.Show import
GHC.Show.showList__ :: (a -> ShowS) -> [a] -> ShowS
is equivalent to
GHC.Show.showList__ :: (a -> (String -> String)) -> [a] -> (String ->
String)
It can be a little confusing but a lot of times you use the same function
prototype and it is useful to just turn it into its own little type to
shorten the types in your code.
On Tue, Sep 24, 2013 at 6:15 AM, yi lu <zhiwudazhanjiangshi at gmail.com>wrote:
> Prelude> :i ShowS
> type ShowS = String -> String -- Defined in `GHC.Show'
>
> It is a type of a function? I cannot understand this type, and don't know
> how to create functions of this type.
>
> And this function "shows"
>
> Prelude> :i shows
> shows :: Show a => a -> ShowS -- Defined in `GHC.Show'
>
> I don't know how this function works.
>
> Yi
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130924/38cf4446/attachment.htm>
More information about the Beginners
mailing list