Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  How to understand the type "ShowS"? (yi lu)
   2. Re:  How to understand the type "ShowS"? (yi lu)
   3. Re:  How to understand the type "ShowS"? (David McBride)
   4.  vim - quickly take suggestions from ghc in case  of compile
      errors (Nathan H?sken)
   5.  Split list by list using Continuations (Dmitriy Matrosov)


----------------------------------------------------------------------

Message: 1
Date: Tue, 24 Sep 2013 20:21:52 +0800
From: yi lu <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to understand the type "ShowS"?
Message-ID:
        <cakcmqqybkyqewka0zgybrmdwnl7i1xrwtp9b_rfdqtxccz3...@mail.gmail.com>
Content-Type: text/plain; charset="iso8859-7"

I have found the link of difference list. Maybe this helps.

http://www.haskell.org/haskellwiki/Difference_list


On Tue, Sep 24, 2013 at 7:54 PM, yi lu <[email protected]>wrote:

>
>
>
> On Tue, Sep 24, 2013 at 7:47 PM, Shrivats <[email protected]> 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" <[email protected]> wrote:
>>
>>>
>>> On Tue, Sep 24, 2013 at 6:54 PM, Lyndon Maydwell <[email protected]>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 
>>>> <[email protected]>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
>>>>> [email protected]
>>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> Beginners mailing list
>>>> [email protected]
>>>> http://www.haskell.org/mailman/listinfo/beginners
>>>>
>>>>
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130924/8d976e9b/attachment-0001.html>

------------------------------

Message: 2
Date: Tue, 24 Sep 2013 20:36:33 +0800
From: yi lu <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to understand the type "ShowS"?
Message-ID:
        <CAKcmqqyP3SnPmzYQjkU8PApoz=vr03nr5vpmgraxtnha7_n...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

On Tue, Sep 24, 2013 at 7:50 PM, Kim-Ee Yeoh <[email protected]> wrote:

>
> On Tue, Sep 24, 2013 at 6:43 PM, yi lu <[email protected]>wrote:
>
>> I have just looked at the API of Prelude, and I remember similar
>> definition for parallel haskell.
>
>
> How far have you gotten with LYAH? Or Hutton's textbook?
>
> I don't know this problem is revealed in LYAH, and I will check it now.
Thanks.


> What does a search on "haskell intro type system" reveal?
>
> -- Kim-Ee
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130924/b197571c/attachment-0001.html>

------------------------------

Message: 3
Date: Tue, 24 Sep 2013 09:05:45 -0400
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to understand the type "ShowS"?
Message-ID:
        <can+tr43g5pn3rdebjiukucm2-3mqqejjbdocj1il2qogsjf...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

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 <[email protected]>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
> [email protected]
> 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-0001.html>

------------------------------

Message: 4
Date: Tue, 24 Sep 2013 16:08:24 +0200
From: Nathan H?sken <[email protected]>
To: Haskell Beginners Mailinglist <[email protected]>
Subject: [Haskell-beginners] vim - quickly take suggestions from ghc
        in case of compile errors
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hey,

ghc has a nice feature, when one compiles a haskell program and has made 
a spelling error, it suggest similar names that could be what one meant.

Example:
Data.hs:24:44:
     Not in scope: `mont_'
     Perhaps you meant `month_' (line 10)

Is there a vim plugin that takes advantage of this? So that I can 
compile my haskell project, and for errors where ghc has a suggestion 
insert the suggestion with a simple key press?

Thanks!
Nathan


------------------------------

Message: 5
Date: Tue, 24 Sep 2013 18:30:24 +0400
From: Dmitriy Matrosov <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Split list by list using Continuations
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII

Hi.

I want to write a function to split list by list. E.g. if i have input list
"aXYbc" and list "XY" is separator, then result should be ["a", "bc"]. And i
want to write it using Continuations. Here is my version, which implements
following scheme:

   ..  >>= f x(k+1) >>= f x(k+2) >>= f x(k+3) >>= f x(k+4) >>= ..
              ....(match to sep) ..........>+
                                            | (failed)
              +<= (continuation backward) <=+
(add to word) |
              \------->..(match to sep).....+
                                            | (succeed)
                                            +------>+.. (match to sep) ..

> import qualified Data.Foldable as F
> import Control.Applicative
> import Control.Monad.Cont
>
> nullF :: F.Foldable t => t a -> Bool
> nullF               = null . F.toList
>
> addToHeadA :: Alternative f => a -> [f a] -> [f a]
> addToHeadA x []       = [pure x]
> addToHeadA x (y : ys) = (pure x <|> y) : ys
>
> type Sep a          = [a]   -- Word separator.
> type Res5 f a       = [f a] -- Result.
> data SplitState5 m f a  = MaybeSep5 (Sep a) (Res5 f a)
>                                     (() -> m (SplitState5 m f a))
>                         | Word5 (Res5 f a)
> 
> split5M :: (Eq a, F.Foldable t, Alternative f, MonadCont m) =>
>            Sep a -> t a -> m (Res5 f a)
> split5M ks0 xs
>   | nullF xs        = return []
>   | otherwise       = F.foldrM go (Word5 [empty]) xs >>= finalize
>   where
>     ksR             = reverse ks0
>     --go :: (Eq a, MonadCont m) =>
>     --      a -> SplitState5 m f a -> m (SplitState5 m f a)
>     go _ (MaybeSep5 []  _  h) = h ()
>     go x (MaybeSep5 [k] zs _)
>       | x == k      = return (Word5 (empty : zs))
>     go x (MaybeSep5 (k : ks) zs h)
>       | x == k      = return (MaybeSep5 ks zs h)
>       | otherwise   = h ()
>     go x (Word5 zs) = callCC $ \r -> do
>                         callCC $ \h -> go x (MaybeSep5 ksR zs h) >>= r
>                         return (Word5 (x `addToHeadA` zs))
>     finalize :: (Alternative f, MonadCont m) =>
>                 SplitState5 m f a -> m (Res5 f a)
>     finalize (Word5 zs)         = return zs
>     finalize (MaybeSep5 _ _ h)  = h () >> return undefined
>

And i have several questions about this implementation:
    - Is it good CPS implementation? Or there is much simpler and better one?
    - Can it be improved?
    - Can i make it more generic?
    - Would non-CPS implementation be better or simpler, than this one?

--
    Dmitriy Matrosov



------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 63, Issue 37
*****************************************

Reply via email to