Send Beginners mailing list submissions to
[email protected]
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
[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. Code review: Go challenge #1 in Haskell
(Ramakrishnan Muthukrishnan)
2. Re: Dipping Toes Into Haskell (Timothy Washington)
3. Support for Maildir (Elias Diem)
4. Re: Code review: Go challenge #1 in Haskell (Henk-Jan van Tuyl)
5. Re: Code review: Go challenge #1 in Haskell
(Ramakrishnan Muthukrishnan)
----------------------------------------------------------------------
Message: 1
Date: Sun, 22 Mar 2015 18:46:14 +0530
From: Ramakrishnan Muthukrishnan <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Code review: Go challenge #1 in Haskell
Message-ID:
<1427030174.3627139.243629570.07376...@webmail.messagingengine.com>
Content-Type: text/plain; charset="UTF-8"
Hello Haskellers:
A few weeks ago, there was this thing called "Go challenge" and a
problem was posted? on decoding a binary format and printing out the
drum sequences in the input binary file.
I made a Haskell solution and would love to get some code reviews.
<https://github.com/vu3rdd/drum>
One of the input files given does not have the full bitstream and my
program cannot parse that yet. I had been thinking about using a Monad
transformer to make a `Get (Maybe) a' and output whatever it could parse
and leave the rest behind, instead of failing completely.
? http://golang-challenge.com/go-challenge1/
(fwiw, the challenge is over.)
Thanks in advance,
Ramakrishnan
------------------------------
Message: 2
Date: Sun, 22 Mar 2015 09:33:18 -0700
From: Timothy Washington <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Dipping Toes Into Haskell
Message-ID:
<CAADtM-ZiG-Z2r=uMm22LSjQw54p4j=mvp+psmrzp72zpvn_...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
So I've finally had a chance to revisit my tictactoe game.
import Control.Lens
data Piece = X | O | E deriving Show
type Row = [Piece]
type Board = [Row]
*data Position = Int Int deriving Show*
-- put an X or O in a position
*move :: Board -> Piece -> Position -> Board*
move board piece position = board
main :: IO ()
main = putStrLn "Hello World"
-- using Lenses
-- https://github.com/ekmett/lens/wiki/Examples
-- http://lens.github.io/tutorial.html
--
http://blog.jakubarnold.cz/2014/07/14/lens-tutorial-introduction-part-1.html
--let r1 = (E,E,E)
--let r2 = (E,E,E)
--let r3 = (E,E,E)
--let board = (r1,r2,r3)
Now, if I want to make a move, I'll want to set a *piece* on a *position*,
on a *board*. Let's assume the board has the following shape.
?> let r1 = (E,E,E)
?> let r2 = (E,E,E)
?> let r3 = (E,E,E)
?> let board = (r1,r2,r3)
((E,E,E),(E,E,E),(E,E,E))
To return an updated board, I dug around and *i)* couldn't find a core
Haskell equivalent to Clojure's update-in
<http://clojuredocs.org/clojure.core/update-in>. *ii)* Zippers only deal
with trees of left / right nodes. *iii)* So that left me with Control.Lens
<https://github.com/ekmett/lens/wiki/Examples>. Now I can easily inspect
and update the board like so.
?> board^*._**2._1*
E
?> set (*_2._1*) 42 board
((E,E,E),(42,E,E),(E,E,E))
I can then parameterize _2 or _1 like so.
?> let a = _2
?> board ^. a
(E,E,E)
But I can't figure out how to include that parameter's type into a
*Position* type definition. I've tried these unsuccessfully.
*data Position = Int Int deriving Show -- original type definition*
*data Position = Simple Lens (Int a) (Int a) deriving Show -- failing try
1*
move :: Board -> Piece -> Position -> Board
move board piece position = set (position) piece board -- want to use this
instead of "set (*_2._1*) 42 board"
Any ideas?
:)
Tim Washington
Interruptsoftware.com <http://interruptsoftware.com>
On Thu, Mar 12, 2015 at 5:18 PM, Timothy Washington <[email protected]>
wrote:
> Veeery nice. Thanks for your insights.
>
> The Typeclass stuff making a lot more sense now. And hence ghc-mod's
> (Interactive-Haskell's) behaviour makes more sense to me. It's working like
> a charm.
>
> I'll play around with nested list manipulation this evening.
>
>
> Cheers
>
> Tim Washington
> Interruptsoftware.com <http://interruptsoftware.com>
>
>
> On Thu, Mar 12, 2015 at 8:03 PM, Mike Meyer <[email protected]> wrote:
>
>> On Thu, Mar 12, 2015 at 6:02 PM, Timothy Washington <[email protected]>
>> wrote:
>>
>>> To get started, I'm trying to implement a simple *tictactoe* game. And
>>> I would like to be able to represent a Piece on the board, as either the
>>> string "X" or "O". This is what I have so far.
>>>
>>> module Main where
>>>
>>> data Piece = X | O
>>> type Row = [Piece]
>>> type Board = [Row]
>>>
>>> -- put an X or O in a position
>>> move :: Board -> Piece -> Board
>>> move board piece = board
>>>
>>> -- check win vertically
>>> -- check win horizontally
>>> -- check win diagonally
>>>
>>> main :: IO ()
>>> main = putStrLn "Hello World"
>>>
>>>
>>>
>>> *A)* Now, I'd like to be able to *load code interactively*, preferably
>>> within emacs. However I don't have access to my types with *ghci* or
>>> *ghc-mod
>>> (Interactive-Haskell)*. In either case, this call fails with the below
>>> error.
>>>
>>>
>>> let p = Piece X
>>> <interactive>:20:9-13: Not in scope: data constructor `Piece'
>>>
>>>
>> Piece is the data TYPE. It has two constructors, X, and O. If you load
>> your module into ghci, you can do ":t X" to get the type of X, which is
>> Piece. You want to do "let p = X" here.
>>
>> Check your mode docs while editing the haskell file. There should be a
>> command to load the current buffer into a ghci running in an interactive
>> emacs buffer.
>>
>>
>>> *B)* And how do I make a *custom datatype* that's one of two strings
>>> (enumeration of either "X" or "O"). Cabal builds and runs the abouve code,
>>> so I know it can compile. But I'm confused as to where X or O is defined,
>>> and how I would supply it as an input.
>>>
>>
>>
>> As noted, you can derive "Show" so that Piece types print as "X" and "O".
>> Similarly, you can derive "Read":
>>
>> data Piece = X | O deriving (Show, Read)
>>
>> so that you can then read "X" and get back an X when the context calls
>> for a Piece value:
>>
>> *Main> read "X" :: Piece
>>
>> X
>>
>> However, this isn't used a lot, as it tends to be slow and not very
>> flexible for more complex types. For instance, it will let you read in
>> lists of Pieces and lists of lists, but you'l lhave to use the list syntax,
>> not something that looks like an actual board when printed.
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150322/7f429bb5/attachment-0001.html>
------------------------------
Message: 3
Date: Sun, 22 Mar 2015 19:56:52 +0100
From: Elias Diem <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Support for Maildir
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Hi there
Am I right that there are no up-to-date packages/libraries
to process email in Maildir format?
--
Greetings
Elias
------------------------------
Message: 4
Date: Sun, 22 Mar 2015 23:25:32 +0100
From: "Henk-Jan van Tuyl" <[email protected]>
To: [email protected], "Ramakrishnan Muthukrishnan"
<[email protected]>
Subject: Re: [Haskell-beginners] Code review: Go challenge #1 in
Haskell
Message-ID: <op.xvw68zdepz0j5l@alquantor>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
delsp=yes
On Sun, 22 Mar 2015 14:16:14 +0100, Ramakrishnan Muthukrishnan
<[email protected]> wrote:
> Hello Haskellers:
>
> A few weeks ago, there was this thing called "Go challenge" and a
> problem was posted? on decoding a binary format and printing out the
> drum sequences in the input binary file.
>
> I made a Haskell solution and would love to get some code reviews.
>
> <https://github.com/vu3rdd/drum>
in line
put _ = do BinaryPut.putWord8 0 -- we don't care about writing
the 'do' is not necessary, as there is only one action;
you could also write:
put _ = undefined -- we don't care about writing
or:
put _ = error "put is not implemented"
The line
(intercalate "\n" $ map show tracks')
can be simplified to
(unlines $ map show tracks')
The line
putStrLn (show (runGet get bs :: Splice))
can be simplified to
print (runGet get bs :: Splice)
as print is the same as
putStrLn . show
Instead of:
else
do
track <- getTrack
tracks' <- getTracks
return (track:tracks')
you could write:
else liftM2 (:) getTrack getTracks
or:
else getTrack ^:^ getTracks
where
(^:^) = liftM2 (:)
(import Control.Monad first)
The function splitN is the same as chunksOf from the package split; I
found this by entering the type of splitN as a search string in Hoogle.
You can use hlint (from Hackage) to get some hints for possible
improvements of the code.
Regards,
Henk-Jan van Tuyl
--
Folding@home
What if you could share your unused computer power to help find a cure? In
just 5 minutes you can join the world's biggest networked computer and get
us closer sooner. Watch the video.
http://folding.stanford.edu/
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--
------------------------------
Message: 5
Date: Mon, 23 Mar 2015 06:46:12 +0530
From: Ramakrishnan Muthukrishnan <[email protected]>
To: "Henk-Jan van Tuyl" <[email protected]>, [email protected]
Subject: Re: [Haskell-beginners] Code review: Go challenge #1 in
Haskell
Message-ID:
<1427073372.3755259.243804762.7ce52...@webmail.messagingengine.com>
Content-Type: text/plain; charset="UTF-8"
On Mon, Mar 23, 2015, at 03:55 AM, Henk-Jan van Tuyl wrote:
> On Sun, 22 Mar 2015 14:16:14 +0100, Ramakrishnan Muthukrishnan
> <[email protected]> wrote:
>
> > Hello Haskellers:
> >
> > A few weeks ago, there was this thing called "Go challenge" and a
> > problem was posted? on decoding a binary format and printing out the
> > drum sequences in the input binary file.
> >
> > I made a Haskell solution and would love to get some code reviews.
> >
> > <https://github.com/vu3rdd/drum>
>
>
> in line
> put _ = do BinaryPut.putWord8 0 -- we don't care about writing
> the 'do' is not necessary, as there is only one action;
> you could also write:
> put _ = undefined -- we don't care about writing
> or:
> put _ = error "put is not implemented"
>
>
> The line
> (intercalate "\n" $ map show tracks')
> can be simplified to
> (unlines $ map show tracks')
>
>
> The line
> putStrLn (show (runGet get bs :: Splice))
> can be simplified to
> print (runGet get bs :: Splice)
> as print is the same as
> putStrLn . show
>
>
> Instead of:
> else
> do
> track <- getTrack
> tracks' <- getTracks
> return (track:tracks')
> you could write:
> else liftM2 (:) getTrack getTracks
> or:
> else getTrack ^:^ getTracks
> where
> (^:^) = liftM2 (:)
> (import Control.Monad first)
Hello Henk-Jan,
Thanks a lot for all the suggestions.
> You can use hlint (from Hackage) to get some hints for possible
> improvements of the code.
Thanks. I ran HLint and it gave some more suggestions. Incorporated all
the suggestions, thanks a lot.
Ramakrishnan
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 81, Issue 53
*****************************************