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. Re: Dipping Toes Into Haskell (Bob Hutchison)
2. Haskell Compiler (Shishir Srivastava)
3. Re: Haskell Compiler
(Sumit Sahrawat, Maths & Computing, IIT (BHU))
4. Re: Haskell Compiler (Bahad?r Do?an)
5. Re: Haskell Compiler (Mike Meyer)
6. Re: Dipping Toes Into Haskell (Timothy Washington)
----------------------------------------------------------------------
Message: 1
Date: Tue, 24 Mar 2015 09:13:03 -0400
From: Bob Hutchison <[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: <[email protected]>
Content-Type: text/plain; charset=utf-8
> On Mar 23, 2015, at 10:38 PM, Timothy Washington <[email protected]> wrote:
>
[snip]
> So ultimately I want a function signature that lets me pass in a lens
> position.
>
> -- 1. these 2 don't compile together
>
> data Position = Position Int Int deriving Show
>
> move :: Board -> Piece -> Position -> Board
> move board piece position = set (position) piece board
>
>
> -- 2. and using the (:t ...) type definition abouve, none of these work
>
> move :: Board -> Piece -> ((Field2 s t a b, Functor f) => (a -> f b) -> s ->
> f t) -> Board
> -- move :: Board -> Piece -> ((a -> f b) -> s -> f t) -> Board
> -- move :: Board -> Piece -> (a -> f b) -> Board
> -- move :: Board -> Piece -> (s -> f t) -> Board
>
> move board piece position = set (position) piece board
>
> -- 3. so the below code compiles, but doesn't do me much good... I need
> Position to be a lens, such that I can use A) set (position) piece board ,
> instead of B) set (_2._1) 42 board
>
> module Main where
>
> import Control.Lens
>
> data Piece = X | O | E deriving Show
> type Row = [Piece]
> type Board = [Row]
> data Position = Int Int deriving Show
>
> move :: Board -> Piece -> Position -> Board
> move board piece position = board
You seem set on lenses. So if you write that move function like this (in case
anyone?s wondering, I happen to know this isn?t a homework question):
data Piece = X | O | E deriving Show
move :: a -> b1 -> ASetter a b a1 b1 -> b
move board position piece = board & position .~ piece
This?ll work. But how are you going to get the position? If you?re given an
integer based coordinate, as you seem to want from your definitions of
Position, then you?re going to have to do something ugly.
Why not just go with an array and be done with it? Something like this (with
your original definition of Piece):
import Data.Array
data Piece' = X | O | E deriving Show
type Position' = (Int,Int)
type Board' = Array Position? Piece'
board' :: Board'
board' = array ((1,1),(3,3)) [((i,j), E) | i <- [1,2,3], j <- [1,2,3]]
move' :: Board' -> Piece' -> Position' -> Board'
move' board piece pos = board // [(pos, piece)]
If you want a slightly less ugly of looking at the board
import qualified Data.List.Split as S
pp board = mapM_ print $ S.chunksOf 3 $ elems board
will display the board something like:
[E,E,E]
[E,E,E]
[E,E,E]
I hope I didn?t say too much.
Cheers,
Bob
>
> main :: IO ()
> main = putStrLn "Hello World"
>
>
>
> Cheers mate :)
>
> Tim Washington
> Interruptsoftware.com
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
Message: 2
Date: Tue, 24 Mar 2015 13:24:28 +0000
From: Shishir Srivastava <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Haskell Compiler
Message-ID:
<cale5rtsufg_fezfy9tf3p-yy_5hi9vrej75qchcdopvf8lj...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi,
What language is the Haskell compiler writter in ? Is it in Haskell itself
just like gcc is written in 'C' ?
Thanks,
Shishir Srivastava
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150324/aca97a26/attachment-0001.html>
------------------------------
Message: 3
Date: Tue, 24 Mar 2015 18:56:10 +0530
From: "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
<[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Haskell Compiler
Message-ID:
<CAJbEW8MhKkkUxZzi=xwwh5h4kvw8zzrqug1o_j-5z0qe3pu...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
https://github.com/ghc/ghc
It's written in haskell. And a lot of other stuff (including C).
On 24 March 2015 at 18:54, Shishir Srivastava <[email protected]>
wrote:
> Hi,
>
> What language is the Haskell compiler writter in ? Is it in Haskell itself
> just like gcc is written in 'C' ?
>
> Thanks,
> Shishir Srivastava
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
--
Regards
Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150324/28d0da34/attachment-0001.html>
------------------------------
Message: 4
Date: Tue, 24 Mar 2015 15:32:26 +0200
From: Bahad?r Do?an <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Haskell Compiler
Message-ID:
<cao9tusrt0vk3rjjf2gpv9e3rmv1y7zhfb4gqb2gxqxvf+qm...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
For a deeper understanding:
http://www.aosabook.org/en/ghc.html
On Tue, Mar 24, 2015 at 3:24 PM, Shishir Srivastava <
[email protected]> wrote:
> Hi,
>
> What language is the Haskell compiler writter in ? Is it in Haskell itself
> just like gcc is written in 'C' ?
>
> Thanks,
> Shishir Srivastava
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150324/0b26206b/attachment-0001.html>
------------------------------
Message: 5
Date: Tue, 24 Mar 2015 08:40:21 -0500
From: Mike Meyer <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Haskell Compiler
Message-ID:
<CAD=7u2b0t3ffjt7skvjwyt-9e_im4xtaezcsumg-jh_dbrk...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
There's more than one Haskell compiler, just like there's more than one C
compiler. As others have noted, the most popular one (ghc) is written in
haskell. You can find a list of implementations in the wiki:
https://wiki.haskell.org/Implementations.
On Tue, Mar 24, 2015 at 8:24 AM, Shishir Srivastava <
[email protected]> wrote:
> Hi,
>
> What language is the Haskell compiler writter in ? Is it in Haskell itself
> just like gcc is written in 'C' ?
>
> Thanks,
> Shishir Srivastava
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150324/1f98044d/attachment-0001.html>
------------------------------
Message: 6
Date: Tue, 24 Mar 2015 20:37:42 -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-zxtya0jbf0cfax-w+htsrhpsazhczggmc+feuj6c5...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Crickey. You're still the man, lol :)
On Tue, Mar 24, 2015 at 6:13 AM, Bob Hutchison <[email protected]>
wrote:
>
> > On Mar 23, 2015, at 10:38 PM, Timothy Washington <[email protected]>
> wrote:
> >
>
> [snip]
>
> ...
>
> You seem set on lenses. So if you write that move function like this (in
> case anyone?s wondering, I happen to know this isn?t a homework question):
>
> data Piece = X | O | E deriving Show
>
> move :: a -> b1 -> ASetter a b a1 b1 -> b
> move board position piece = board & position .~ piece
>
> This?ll work. But how are you going to get the position? If you?re given
> an integer based coordinate, as you seem to want from your definitions of
> Position, then you?re going to have to do something ugly.
>
This is a good point. I'm not particularly attached to lenses. That was
just the conclusion I reached, in order to reach into and manipulate my
original nested lists. I didn't see a way to do nested list updates in
Data.List, on hackage
<https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-List.html>. But
now I see the difference between that and Data.Array
<https://hackage.haskell.org/package/array-0.5.0.0/docs/Data-Array.html>
(indexable,
etc).
I'll come back to Lenses later on, just because now I'm curious. I'm happy
for the Position to be "*data Position = SomeLensType SomeLensType deriving
Show*", where "*:t _2 => SomeLensType*". Or something else that
accommodates lens' data types.... but baby steps :)
Why not just go with an array and be done with it? Something like this
> (with your original definition of Piece):
>
> import Data.Array
>
> data Piece' = X | O | E deriving Show
> type Position' = (Int,Int)
> type Board' = Array Position? Piece'
>
> board' :: Board'
> board' = array ((1,1),(3,3)) [((i,j), E) | i <- [1,2,3], j <- [1,2,3]]
>
> move' :: Board' -> Piece' -> Position' -> Board'
> move' board piece pos = board // [(pos, piece)]
>
This works swimmingly. So excellent point.
If you want a slightly less ugly of looking at the board
>
> import qualified Data.List.Split as S
>
> pp board = mapM_ print $ S.chunksOf 3 $ elems board
>
> will display the board something like:
>
> [E,E,E]
> [E,E,E]
> [E,E,E]
>
> I hope I didn?t say too much.
>
Not at all. These are exactly the kinds of hints that I need. In fact, with
the *//* and *array* functions, this makes a lot of sense. And I used that
and the board beautifier chunk, to create this.
import Data.Array
import qualified Data.List.Split as S
data Piece' = X | O | E deriving Show
type Position' = (Int,Int)
type Board' = Array Position' Piece'
board' :: Board'
board' = array ((1,1),(3,3)) [((i,j), E) | i <- [1,2,3], j <- [1,2,3]]
ppb' :: Board' -> IO()
ppb' b = mapM_ print $ S.chunksOf 3 $ elems b
move' :: Board' -> Piece' -> Position' -> Board'
move' board piece pos = board // [(pos, piece)]
Now, I can pass in the board, piece, and position, to get my expected
result.
?> board'
array ((1,1),(3,3))
[((1,1),E),((1,2),E),((1,3),E),((2,1),E),((2,2),E),((2,3),E),((3,1),E),((3,2),E),((3,3),E)]
?> let b1 = move' board' *X* (1,3)
?> b1
array ((1,1),(3,3))
[((1,1),E),((1,2),E),((1,3),X),((2,1),E),((2,2),E),((2,3),E),((3,1),E),((3,2),E),((3,3),E)]
?> ppb' b1
[E,E,*X*]
[E,E,E]
[E,E,E]
Cheers,
> Bob
Cool !
Cheers :)
Tim Washington
Interruptsoftware.com <http://interruptsoftware.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150324/f10e4f6d/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 81, Issue 58
*****************************************