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-request@haskell.org
You can reach the person managing the list at
beginners-owner@haskell.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. cabal repl issue (Lai Boon Hui)
2. Re: cabal repl issue (David McBride)
3. Re: Monadic functions definitions for free monadic DSL
(Sumit Raja)
4. Re: Monadic functions definitions for free monadic DSL
(Kim-Ee Yeoh)
------------------------------------------------------------ ----------
Message: 1
Date: Fri, 21 Oct 2016 22:35:19 +0800
From: Lai Boon Hui <laiboonh@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] cabal repl issue
Message-ID:
<CAJdQggnSvw8z7V+SBY=y2TEfhpcK2znLHpkp9i+Edq5QAgXM7w@mail. >gmail.com
Content-Type: text/plain; charset="utf-8"
Hi all,
when i execute cabal repl i get this:
<interactive>:1:8: error:
Not in scope: ‘System.Directory.getCurrentDirectory’
No module named ‘System.Directory’ is imported.
because my ghci.conf has
:def pwd (\_-> System.Directory.getCurrentDirectory >>= print >> return "")
Does anyone know how i can include System.Directory somehow even though its
not used in my cabal project?
--
Best Regards,
Boon Hui
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/ >attachments/20161021/81951b8d/ attachment-0001.html
------------------------------
Message: 2
Date: Fri, 21 Oct 2016 10:56:55 -0400
From: David McBride <toad3k@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] cabal repl issue
Message-ID:
<CAN+Tr42JiQ3x-MtrZXthx=PHjnJ+RH7zj3HJGQ6L+j7Y3cFcfw@mail. >gmail.com
Content-Type: text/plain; charset="utf-8"
Just do this:
:m +System.Directory
:def pwd (\_ -> getCurrentDirectory >>= print >> return "")
On Fri, Oct 21, 2016 at 10:35 AM, Lai Boon Hui <laiboonh@gmail.com> wrote:
> Hi all,
>
> when i execute cabal repl i get this:
>
> <interactive>:1:8: error:
>
> Not in scope: ‘System.Directory.getCurrentDirectory’
>
> No module named ‘System.Directory’ is imported.
> because my ghci.conf has
> :def pwd (\_-> System.Directory.getCurrentDirectory >>= print >> return
> "")
>
> Does anyone know how i can include System.Directory somehow even though
> its not used in my cabal project?
>
> --
> Best Regards,
> Boon Hui
>
> _______________________________________________
> 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/20161021/81bfe668/ attachment-0001.html
------------------------------
Message: 3
Date: Sat, 22 Oct 2016 12:14:15 +1100
From: Sumit Raja <sumitraja@gmail.com>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Monadic functions definitions for
free monadic DSL
Message-ID:
<CAD4nrSf68uPFaHKpHN01wJjhhMMO5tSBQqHfM1cBogphxvUihg@mail. >gmail.com
Content-Type: text/plain; charset=UTF-8
> I feel like if you can figure out what you actually want Accept to do, it
> will become clearer. Here's my attempt. Accept takes a chan, takes a
> procedure to loop on, a procedure to accept on, and then returns the server
> chan to continue the loop. I don't know if this is entirely right, but it
> type checks and hopefully it will give you some ideas.
As you've said Accept needs refinement. I tried writing a interpretUDP
which doesn't have an accept loop but does have a bind + listen. I
suspect that accept needs to move into the interpretTCP somehow and
the DSL needs to be Bind or similar. Bind makes more sense as well if
I wanted to write a pipes or a chan based interpreter.
Thanks for the rewrite and the pointers.
-Sumit
------------------------------
Message: 4
Date: Sat, 22 Oct 2016 08:27:32 +0700
From: Kim-Ee Yeoh <ky3@atamo.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Monadic functions definitions for
free monadic DSL
Message-ID:
<CAPY+ZdQfO_+42BGYd2zAL6bvdgQuCadjgADj0T_ >7C7ogk-Xvpg@mail.gmail.com
Content-Type: text/plain; charset="utf-8"
Dear Sumit,
You are right that there's something's fishy about the free monadic
modeling of accept.
The following parallel construction will prove instructive:
The native effect:
send :: chan -> ByteString -> IO Bool
is modeled in the free monad by the constructor for the base functor
Send :: chan -> ByteString -> (Bool -> next) -> NetworkActivity chan next
which is the data wrapping used in the value level
sendit :: chan -> ByteString -> Free (NetworkActivity chan) Bool
sendit chan buf = liftF (Send chan buf identity)
Analogously, the native
accept :: chan -> IO chan
is modeled by
Accept :: chan -> (chan -> next) -> NetworkActivity chan next
used in
acc :: chan -> Free (NetworkActivity chan) chan
acc chan = liftF (Accept chan identity)
Except that you used a different constructor for the base functor. Not
Accept :: chan -> (chan -> next) -> NetworkActivity chan next
but
Accept :: chan -> next -> (chan -> next) -> NetworkActivity chan next
which is equivalent to
Accept :: chan -> (Maybe chan -> next) -> NetworkActivity chan next
The new free monadic term that substitutes for the native accept is the
same like before
acc chan = liftF (Accept chan identity)
only with a different type
acc :: chan -> Free (NetworkActivity chan) (Maybe chan)
modeling a native
accept :: chan -> IO (Maybe chan)
Given a native API, its free monad encoding is entirely boilerplate. I
wrote about the boilerplate process here (skip the sections that don't
concern you):
http://www.atamo.com/articles/free-monads-wont-detox-your- colon/
Best, Kim-Ee
-- Kim-Ee
On Fri, Oct 14, 2016 at 6:44 AM, Sumit Raja <sumitraja@gmail.com> wrote:
> > I would really like to help you, but without your imports, packages, etc,
> > it is really hard to interpret your program. Like where does decodeUtf8
> > come from, or receive, or TCPSocket? If they are functions you wrote, I
> > don't need their code, the types would be sufficient.
> >
> Imports are:
>
> import Protolude
> import Control.Monad.Free
> import System.Socket
> import System.Socket.Family.Inet
> import System.Socket.Type.Stream
> import System.Socket.Protocol.TCP
> import Control.Exception ( bracket, catch )
> import Data.ByteString as BS (uncons)
>
> decodeUtf8 :: ByteString -> Text
> encodeUtf8 :: Text -> ByteString
>
> I'm using the socket library for the actual networking
> (https://hackage.haskell.org/package/socket-0.6.0.1 )
>
> type TCPSocket = Socket Inet Stream TCP
> receive :: Socket f t p -> Int -> MessageFlags -> IO ByteString Source
> send :: Socket f t p -> ByteString -> MessageFlags -> IO Int
> accept :: (Family f, Storable (SocketAddress f)) => Socket f t p
> -> IO (Socket f t p, SocketAddress f)
>
> If it helps the full source is at
> https://bitbucket.org/sumitraja/network-free/src/
> a4fcbc74c9e178e81d8b10b60d912b32c542b661/src/Lib.hs.
>
> Looking forward to your assistance.
>
> Thanks
>
> Sumit
> _______________________________________________
> 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/20161022/742c58ac/ 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 100, Issue 14
******************************************