[Haskell-beginners] How to understand the type "ShowS"?
yi lu
zhiwudazhanjiangshi at gmail.com
Tue Sep 24 13:54:08 CEST 2013
On Tue, Sep 24, 2013 at 7:47 PM, Shrivats <shrvtsnvs at gmail.com> wrote:
> What does `show "asdf"` give you in ghci? What Lyndon showed you was that
> this function is equivalent to `shows x s = show x ++ s`.
>
> Ah, it works a bit like "++" ?
> Have fun,
>
> Shrivats
> On Sep 24, 2013 5:09 PM, "yi lu" <zhiwudazhanjiangshi at gmail.com> wrote:
>
>>
>> On Tue, Sep 24, 2013 at 6:54 PM, Lyndon Maydwell <maydwell at gmail.com>wrote:
>>
>>> Looks like it's a convenience for building up a compositions of "Show"s.
>>>
>>> ShowS is indeed a synonym for a function. The type of shows alone isn't
>>> enough to figure out how it behaves exactly, but testing it out in GHCi is
>>> telling:
>>>
>>>
>>> > [Prelude] λ :i ShowS
>>> > type ShowS = String -> String -- Defined in `GHC.Show'
>>> > [Prelude] λ :i shows
>>> > shows :: Show a => a -> ShowS -- Defined in `GHC.Show'
>>> > [Prelude] λ shows "asdf" "qwer"
>>> > "\"asdf\"qwer"
>>>
>>> I don't know the meaning of this result.
>>
>>
>>
>>>
>>> On Tue, Sep 24, 2013 at 8:15 PM, 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
>>>>
>>>>
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
> _______________________________________________
> 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/0ae01f1c/attachment.htm>
More information about the Beginners
mailing list