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: Simpler than lifting (Adrian May)
2. haddock parse error (Christopher Howard)
3. Re: haddock parse error (Nikita Danilenko)
4. compiling a dynamic executable (Markus L?ll)
5. Re: A good data structure for representing a tic-tac-toe
board? (emacstheviking)
----------------------------------------------------------------------
Message: 1
Date: Tue, 19 Mar 2013 11:59:33 +0800
From: Adrian May <[email protected]>
Subject: Re: [Haskell-beginners] Simpler than lifting
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<cad-ubzg17h95o_qwbhext_+y1wy29gfmzou-5uy+asmuag8...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
So function application itself is the functor, i.e., the box-like thing,
right? Lifting a function of values to work on boxes containing those
values corresponds with lifting a function of values to work on functions
yielding those values. Right? In which case, fishing something out of the
box corresponds with applying the function. Why not? With record notation
you use a function to fish out a field anyway. That's very interesting.
Now I have this:
type Amount = Float
type Moment = Day -- from Data.Time.Calendar
data Period = Period Moment Moment
type Flowfunc = Period -> Amount
f0 = const 0
-- Add and subtract flowfuncs
infixl 6 ~+, ~-
(~+), (~-) :: Flowfunc -> Flowfunc -> Flowfunc
f ~+ g = (+) <$> f <*> g
f ~- g = (-) <$> f <*> g
But here I still seem to be being naive again...
-- Multiply flowfunc by a float
infixl 7 ~*
(~*) :: Float -> Flowfunc -> Flowfunc
f ~* n = \p -> n * (f p)
-- or with the params the other way around
I guess I could write:
f ~* n = (*) <$> f <*> const n
but it seems clunky. Should it be a monad?
How about:
-- Sum a list of them
sumf :: [Flowfunc] -> Flowfunc
sumf l = foldl (~+) f0 l
TIA,
Adrian.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130319/fd157ed8/attachment-0001.htm>
------------------------------
Message: 2
Date: Mon, 18 Mar 2013 22:41:23 -0800
From: Christopher Howard <[email protected]>
Subject: [Haskell-beginners] haddock parse error
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi. I tried to run haddock on a file with this content:
code:
--------
{-|
The 'summation' function provides the same function as summation or sigma
notation. The first argument the starting index number. The second
argument
is the ending index number. The third argument is a function representing
the formula for each term.
-}
summation :: (Eq a, Num a1, Num a) => a -> a -> (a -> a1) -> a1
summation i n f | i == n = f i
| otherwise = f i + summation (i + 1) n f
...snip...
--------
And I get
quote:
--------
$ haddock summation.hs
summation.hs:7:1: parse error on input `summation'
--------
What is wrong with it? (The code runs fine with GHC.)
$ haddock --version
Haddock version 2.10.0, (c) Simon Marlow 2006
Ported to use the GHC API by David Waern 2006-2008
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.4.1
--
frigidcode.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 555 bytes
Desc: OpenPGP digital signature
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130318/1270e6b3/attachment-0001.pgp>
------------------------------
Message: 3
Date: Tue, 19 Mar 2013 09:20:15 +0100
From: Nikita Danilenko <[email protected]>
Subject: Re: [Haskell-beginners] haddock parse error
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi,
I believe, the module containing the function summation needs a header.
If I add a header, the parse error disappears. This problem may be
explained by [1], where the description probably implies that there is a
module header.
I hope that helps,
Nikita
[1] http://www.haskell.org/haddock/doc/html/ch03s03.html
On 19/03/13 07:41, Christopher Howard wrote:
> Hi. I tried to run haddock on a file with this content:
>
> code:
> --------
> {-|
> The 'summation' function provides the same function as summation or sigma
> notation. The first argument the starting index number. The second
> argument
> is the ending index number. The third argument is a function representing
> the formula for each term.
> -}
> summation :: (Eq a, Num a1, Num a) => a -> a -> (a -> a1) -> a1
> summation i n f | i == n = f i
> | otherwise = f i + summation (i + 1) n f
>
> ...snip...
> --------
>
> And I get
>
> quote:
> --------
> $ haddock summation.hs
>
> summation.hs:7:1: parse error on input `summation'
> --------
>
> What is wrong with it? (The code runs fine with GHC.)
>
> $ haddock --version
> Haddock version 2.10.0, (c) Simon Marlow 2006
> Ported to use the GHC API by David Waern 2006-2008
>
> $ ghc --version
> The Glorious Glasgow Haskell Compilation System, version 7.4.1
>
>
>
>
> _______________________________________________
> 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/20130319/c3ccd6b8/attachment-0001.htm>
------------------------------
Message: 4
Date: Tue, 19 Mar 2013 09:50:40 +0100
From: Markus L?ll <[email protected]>
Subject: [Haskell-beginners] compiling a dynamic executable
To: [email protected], [email protected]
Message-ID:
<caldaiubssjaz4urax+jcc2sepe6fbuhowhu+j9qutburnxn...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Hi!
I'm trying to compile a dynamic executable in Debian on a x86_64
architecture with ghc 7.4.1-4 and ghc-dynamic installed.
To compile the program I started from a clean cabal user database, set
the 'shared' and 'executable-dynamic' settings to 'True' in cabal conf
and fired away with 'cabal install' in my package's directory. It
compiled all the libraries fine-- both the static and dynamic --until
it reached compiling my own program, when in stopped with the
following error:
xxx.hs:1:1:
Dynamic linking required, but this is a non-standard build (eg. prof).
You need to build the program twice: once the normal way, and then
in the desired way using -osuf to set the object file suffix.
/usr/bin/ghc returned ExitFailure 1
I don't have profiling enabled (or is it an example of non-standard
build?), but I also don't understand the proposed solution of building
the program twice.
Compiling with "ghc --make -dynamic {-X...}* Main.hs" ends with the
same error.. (I also know there is a multi-step manual way to do it,
so maybe it could pinpoint the problem -- but I haven't tried it yet)
What could be the problem?
--
Markus L?ll
------------------------------
Message: 5
Date: Tue, 19 Mar 2013 09:57:20 +0000
From: emacstheviking <[email protected]>
Subject: Re: [Haskell-beginners] A good data structure for
representing a tic-tac-toe board?
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<caeieuulamck+f2xbjzjcqlwx18mwrlspep9-n7g4bbpuo0t...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Roger,
Without writing any code, and still learning Haskell I personally don't see
anything intrinsically wrong with using a String, it's simple, it works and
what more can you ask from code than that!
I would go so far as to add "\n" after each line so that you can print the
status of the game to the console in one go, then checking for a winning
line would be as simple as writing a function that takes as its input the
String and a list of string offsets which make up a line, with the
assumption that [0] is the first board position, [2] is the end of the
first line and [3] contains the first "\n" character I would (pseudo-code /
made up from keyboard, pebcak may apply) go for this approach:
topLineWin = checkLine myBoard "O" [0,1,2] -- did O win ?
topleftDiagWin = checkLine myBoard "X" [0,5,10] -- did X win ?
botLineWin = checkLine my Board "X" [8,9,10] -- did X win ?
and so on. The implementation of checkLine is left as an exercise for the
reader as they say but by using partial application you can make the code
very readbable. I might even try this myself and post it back for a laugh.
It's surprising sometime the difference between what you think you know and
what you actually know!
Some coding hints and thinking as I go...
topLine = [0,1,2]
topleftDiagWin = [0,5,10]
etc.
winnerO = checkLine myString "O"
winnerX = checkLine myString "X"
checkLine topLine playerCode -- did the top line win?
...
By making the checkLine return a Bool then you can have a list of functions
that you could then pass through the Data.List.all and make it something
like this:
all [ winnerO topLine, winnerO botLine, ... etc]
Just to make the array number clear, here is the complete board:
"\n"
0 1 2 3
4 5 6 7
8 9 10 10
All the best, that's no coding and pure thought for that so YMMV!
Sean Charles.
On 18 March 2013 15:54, Costello, Roger L. <[email protected]> wrote:
> Hi Folks,
>
> Currently I am representing a tic-tac-toe board as a string, with 'X'
> denoting player 1 and 'O' denoting player 2. For example, I represent this
> 2x2 game board:
>
> 'X' |
> -----------------------
> | 'O'
>
> with this string: "X O"
>
> The nice thing about that representation is that it is each to identify
> which cells are filled or empty, and it is easy to mark a cell with an 'X'
> or 'O'.
>
> The problem with the representation is that it is difficult to determine
> when a player has won.
>
> Can you recommend a representation that makes it easy to:
>
> 1. determine when a player has won
> 2. identify cells that are filled or empty
> 3. mark an empty cell
>
> /Roger
>
> _______________________________________________
> 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/20130319/a571166b/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 57, Issue 28
*****************************************