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:  What is operator :| ? (Francesco Ariis)
   2. Re:  What is operator :| ? (John M. Dlugosz)
   3. Re:  Array/Vector like DS in haskell (John M. Dlugosz)
   4. Re:  What is operator :| ? (Francesco Ariis)
   5.  random monad (Dennis Raddle)
   6.  algorithms books or tutorial in haskell (Nishant)
   7. Re:  random monad (Nikita Danilenko)


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

Message: 1
Date: Fri, 28 Mar 2014 07:48:28 +0100
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] What is operator :| ?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Fri, Mar 28, 2014 at 12:54:03AM -0500, John M. Dlugosz wrote:
> More generally, is there some effective way to search for
> non-alphabetical Haskell things?  Google just ignores the
> "punctuation".
> 

You can find :| on Hayoo [1], the other handy place where to
look for APIs stuff being Hoogle [2] (Hoogle is more focused on
'standard' Haskell libraries, Hayoo searches in all Hackage,
both have their usefulness).
>From there, if I need to search, say, a blog post, I will refer
to the name of the typeclass/module/data and feed it to a search
engine (so in this case "data NonEmpty etc. etc.").
Apparently Google ignores punctuation in most cases [3].

Back to the original question

> What is the meaning of :| ?

Clicking on the first occurrence in Hoogle brings me to
Data.List.NonEmpty, where the specific operator is listed as
the lone constructor of |data NonEmpty|.
If the conspicuous name were not enough, checking the code:

    data NonEmpty a = a :| [a]

we can see this looks like a list without the empty-list
constructor.
Does that answer your question?


[1] http://holumbus.fh-wedel.de/hayoo/hayoo.html#0:%3A|
[2] http://www.haskell.org/hoogle/
[3] https://support.google.com/websearch/answer/2466433
[4] 
http://hackage.haskell.org/package/semigroups-0.12.2/docs/Data-List-NonEmpty.html#v::-124-


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

Message: 2
Date: Fri, 28 Mar 2014 01:58:11 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] What is operator :| ?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed

On 3/28/2014 1:41 AM, Tony Morris wrote:
> It is the constructor for a non-empty list (Data.List.NonEmpty).
>
> http://hackage.haskell.org/package/semigroups-0.12.2/docs/Data-List-NonEmpty.html
>

Interesting? this is the page I had found: 
http://www.haskell.org/haskellwiki/Non-empty_list


So why do we need both :| and <| (or cons) ?



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

Message: 3
Date: Fri, 28 Mar 2014 01:59:26 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Array/Vector like DS in haskell
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 3/28/2014 12:30 AM, Nishant wrote:

> Can someone elaborate on how to create a DS which acts like an array or 
> vector and has
> same time complexity ?
>
>
> A list though can act like array but getting value at index i is linear time 
> but in actual
> array it is constant.

I was just reading  http://www.haskell.org/haskellwiki/Arrays





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

Message: 4
Date: Fri, 28 Mar 2014 08:21:46 +0100
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] What is operator :| ?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8

On Fri, Mar 28, 2014 at 01:58:11AM -0500, John M. Dlugosz wrote:
> On 3/28/2014 1:41 AM, Tony Morris wrote:
> >It is the constructor for a non-empty list (Data.List.NonEmpty).
> >
> >http://hackage.haskell.org/package/semigroups-0.12.2/docs/Data-List-NonEmpty.html
> >
> 
> Interesting? this is the page I had found: 
> http://www.haskell.org/haskellwiki/Non-empty_list
> 
> 
> So why do we need both :| and <| (or cons) ?
> 

Look at the definitions and type signatures:

    (<|) :: a -> NonEmpty a -> NonEmpty a
    a <| ~(b :| bs) = a :| b : bs

    (:|) :: a -> [a] -> NonEmpty a
    data NonEmpty a = a :| [a]

(I found the type-sig for (:|) using ghci ":t").
It is now evident that the constructor (:|) takes element/list to
build |NonEmpty a|, while (<|) appends an |a| to a |NonEmpty a|.



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

Message: 5
Date: Fri, 28 Mar 2014 02:10:51 -0700
From: Dennis Raddle <[email protected]>
To: Haskell Beginners <[email protected]>
Subject: [Haskell-beginners] random monad
Message-ID:
        <cakxlvopcz9l3zkchsbv0vakbeyceae7+w5ovhqyleldowxk...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I'm writing a program which uses a lot of pseudorandom numbers, and for
that reason it would be nice to put the StdGen in a state monad.

like let's say I want to combine error handling and storing the StdGen
state.

import Control.Monad.Error
import Control.Monad.State

data RandState = RandState StdGen
-- Er is a monad that combines error handling and pseudorandom state
type Er a = ErrorT String (State RandState) a

-- to access random numbers, I could define things like


erRandomR :: Random r => (r,r) -> Er r
erRandomR (lo, hi) = do
  RandState g <- get
  let (value, g') = randomR (lo, hi) g
  put $ RandState g'
  return value


erRandoms :: Random r => Er [r]
erRandoms = do
  RandState g <- get
  let (g1, g2) = split g
  let values = randoms g1
  put $ RandState g2
  return values


erRandomRs :: Random r => (r,r) -> Er [r]
erRandomRs (lo,hi) = do
  RandState g <- get
  let (g1, g2) = split g
  let values = randomRs (lo,hi) g1
  put $ RandState g2
  return values

-- I could define new ways of using random values, like choosing a random
element of a list

erChooseList :: [a] -> Er a
erChooseList xs = do
  let l = length xs
  when (l==0) (throwError "in randomChooseList, passed null list")
  idx <- erRandomR (0,l-1)
  return $ xs !! idx

However, after I got done with that, I realized that I wanted to add
additional state, maybe a ReaderT , stuff like that--different in different
parts of the program. But I always want access to random numbers with the
same functions: erRandomR, erRandoms, etc.

So I thought

class Monad m => RandMonad m where
  putGen ::  StdGen -> m ()
  getGen :: m StdGen

Then I could make Er an instance of RandMonad, like this

type Er a = ErrorT String (State RandState) a
instance RandMonad Er where
  putGen g = put (RandState g)
  getGen = do RandState g <- get
              return g

Clearly I don't know what I'm doing, because when I tried to run this much
I got the error

"Type synonym Er should have 1 argument, but has been given none."

I tried a bunch of variations of this but got nowhere. Can someone explain
how I should conceive of this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140328/25589174/attachment-0001.html>

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

Message: 6
Date: Fri, 28 Mar 2014 15:15:43 +0530
From: Nishant <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] algorithms books or tutorial in haskell
Message-ID:
        <CAEQDmz4nUsWr0Kb_=xKHoQicBiaFkTo_SYOJqacvj3sN=ay...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi,

Can someone provide me link to some pdf or online tutorial where I can find
backtracking / dynamic programming kind of algorithms discussed in details.


Regards.
Nishant
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140328/b48cbbd5/attachment-0001.html>

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

Message: 7
Date: Fri, 28 Mar 2014 10:46:37 +0100
From: Nikita Danilenko <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] random monad
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140328/fc83b51a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0x76C229F0.asc
Type: application/pgp-keys
Size: 8170 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140328/fc83b51a/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 901 bytes
Desc: OpenPGP digital signature
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140328/fc83b51a/attachment.sig>

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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 69, Issue 43
*****************************************

Reply via email to