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: Using output of head in data constuctor (Josh Friedlander)
2. How to structure an application? (Tilmann)
3. Re: Using output of head in data constuctor (Bob Ippolito)
4. CSES programming problems at https://cses.fi/problemset/
(Doug McIlroy)
5. Re: CSES programming problems at https://cses.fi/problemset/
(Julian Ong)
----------------------------------------------------------------------
Message: 1
Date: Sun, 28 Jun 2020 15:50:20 +0300
From: Josh Friedlander <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Using output of head in data
constuctor
Message-ID:
<CAC2wD73RhuqM747KM4Gx3=Zx+LtkSGMwFopPe5URMyWr9GQ=p...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Thanks Francesco, that works. I don't quite understand what the issue was,
though. Specifically:
- Did the parentheses around (xs) hurt, or were they just redundant?
- Wouldn't the parentheses around (head ...) be binding it as an argument
to whatever comes before (in this case, 3)?
On Sun, 28 Jun 2020 at 14:47, Francesco Ariis <[email protected]> wrote:
> Hello Josh
>
> Il 28 giugno 2020 alle 14:36 Josh Friedlander ha scritto:
> > I want to create a log parser like this:
> >
> > module LogAnalysis where
> > import Log
> >
> > parseMessage :: String -> LogMessage
> > parseMessage xs
> > | length(words(xs)) < 3 = Unknown xs
> > | notElem(head(words(xs)) ["I", "E", "W"]) = Unknown xs
> > | otherwise = LogMessage Info 3 head(words(xs))
> >
> > But GHC gives me "• Couldn't match type ‘[a0] -> a0’ with ‘[Char]’
> > Expected type: String
> > Actual type: [a0] -> a0"
>
> I suspect `LogMessage Info 3 head(words(xs))` is the problem. This is
> the same as writing
>
> LogMessage Info 3 head (words xs)
>
> keeping in mind how whitespace and parentheses work in Haskell. You
> probably want
>
> LogMessage Info 3 (head (words xs))
>
> instead.
> _______________________________________________
> 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/20200628/ed66b91e/attachment-0001.html>
------------------------------
Message: 2
Date: Sun, 28 Jun 2020 16:03:37 +0200
From: Tilmann <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] How to structure an application?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Hi,
I hope to get some advice on how to structure an application. So I
acquire a handle early on that I use all over the app, but I don't want
to pass the handle itself around, but wrap the handle with "commands"
that a) make a nicer api and/or b) only allow specific usecases of the
handle. I tried and failed to use MonadReader in a straightforward way
and now I'm wondering what options there are. Looking forward to your
feedback,
Best,
Tilmann
module Main where
import Control.Monad
import Control.Monad.Reader
import Graphics.UI.WX
import System.IO
-- imagine many more commands like this one
ping :: (MonadReader Handle m, MonadIO m) => m ()
ping = do
h <- ask
liftIO $ hPutStrLn h "ping"
main :: IO ()
main = do
let h = stdout -- in the real app, this handle isn't stdout of course
but opened separately
start $ runReaderT wxApp h
wxApp :: (MonadReader Handle m, MonadIO m) => m ()
wxApp = do
ping -- this works, but I don't need it here..
liftIO $ do
f <- frame [ ]
timer f [ interval := 1000
-- , on command := hputStrLn h "ping" -- this is what I try
to avoid
-- , on command := ping -- of course, this doesn't work, but
it would be so nice..
, enabled := True]
return ()
-- Alternatively
main2 :: IO ()
main2 = do
let h = stdout
start $ runReaderT wxApp2 (mkCommands h)
wxApp2 :: (MonadReader Commands m, MonadIO m) => m ()
wxApp2 = do
commands <- ask
liftIO $ do
f <- frame [ ]
timer f [ interval := 1000
, on command := ping2 commands
, enabled := True]
return ()
data Commands = Commands {
ping2 :: IO ()
-- .. many more
}
mkCommands :: Handle -> Commands
mkCommands h = Commands (hPutStrLn h "ping")
------------------------------
Message: 3
Date: Sun, 28 Jun 2020 07:35:15 -0700
From: Bob Ippolito <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Using output of head in data
constuctor
Message-ID:
<cacwmpm-ndear4dpbgjxjocg_aekbvdrzzqjxtfzh6uj+mz4...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Parentheses in Haskell aren’t really related to function application, they
are only for grouping. It makes more sense if you avoid using them unless
strictly necessary.
In Haskell instead of `f(g(x))` we would write `f (g x)`, and instead of
`f(x,g(y),z)` we would write `f x (g y) z`. You could use more parentheses
but it would be more confusing, such as `(f)(x)(g(y))(z)`.
On Sun, Jun 28, 2020 at 05:50 Josh Friedlander <[email protected]>
wrote:
> Thanks Francesco, that works. I don't quite understand what the issue was,
> though. Specifically:
> - Did the parentheses around (xs) hurt, or were they just redundant?
> - Wouldn't the parentheses around (head ...) be binding it as an argument
> to whatever comes before (in this case, 3)?
>
> On Sun, 28 Jun 2020 at 14:47, Francesco Ariis <[email protected]> wrote:
>
>> Hello Josh
>>
>> Il 28 giugno 2020 alle 14:36 Josh Friedlander ha scritto:
>> > I want to create a log parser like this:
>> >
>> > module LogAnalysis where
>> > import Log
>> >
>> > parseMessage :: String -> LogMessage
>> > parseMessage xs
>> > | length(words(xs)) < 3 = Unknown xs
>> > | notElem(head(words(xs)) ["I", "E", "W"]) = Unknown xs
>> > | otherwise = LogMessage Info 3 head(words(xs))
>> >
>> > But GHC gives me "• Couldn't match type ‘[a0] -> a0’ with ‘[Char]’
>> > Expected type: String
>> > Actual type: [a0] -> a0"
>>
>> I suspect `LogMessage Info 3 head(words(xs))` is the problem. This is
>> the same as writing
>>
>> LogMessage Info 3 head (words xs)
>>
>> keeping in mind how whitespace and parentheses work in Haskell. You
>> probably want
>>
>> LogMessage Info 3 (head (words xs))
>>
>> instead.
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
> _______________________________________________
> 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/20200628/51e9b0f3/attachment-0001.html>
------------------------------
Message: 4
Date: Sun, 28 Jun 2020 11:26:06 -0400
From: Doug McIlroy <[email protected]>
To: [email protected], [email protected]
Subject: [Haskell-beginners] CSES programming problems at
https://cses.fi/problemset/
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
> I'm currently stuck on the Two Knights problem.
Having placed one knight on the board, in how many
places can you put the other?
Doug McIlroy
------------------------------
Message: 5
Date: Sun, 28 Jun 2020 09:00:51 -0700
From: Julian Ong <[email protected]>
To: Doug McIlroy <[email protected]>
Cc: [email protected]
Subject: Re: [Haskell-beginners] CSES programming problems at
https://cses.fi/problemset/
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
There are 8 possibilities and then you can filter them by column and row values
depending on the region of the board you’re interested in.
Julian
On Jun 28, 2020, at 8:26 AM, Doug McIlroy <[email protected]> wrote:
> I'm currently stuck on the Two Knights problem.
Having placed one knight on the board, in how many
places can you put the other?
Doug McIlroy
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 144, Issue 6
*****************************************