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: Constrained polymorphic functions as natural
transformations (Brent Yorgey)
2. POSIX signals and deamons (Emanuel Koczwara)
3. Re: POSIX signals and deamons (Brandon Allbery)
4. Re: POSIX signals and deamons (Emanuel Koczwara)
----------------------------------------------------------------------
Message: 1
Date: Thu, 14 Nov 2013 08:59:11 -0500
From: Brent Yorgey <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Constrained polymorphic functions as
natural transformations
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Hi Matt,
You have some cool ideas here --- though I think there are a few
places what you say doesn't quite make sense, but I think you're on
the right track.
One thing to note first is that the formalism of natural
transformations only covers *some* but not *all* polymorphic
functions. For example, there is no way to view
fix :: (a -> a) -> a
as a natural transformation, because (a -> a) does not correspond to a
functor over a. In general one must consider what are called
*di*natural transformations. (I ought to write a blog post about
this.) In any case, this is a bit of a digression---simple natural
transformations suffice for a great many "real world" examples---but I
thought I would mention it in case you want to look it up later.
On Wed, Oct 30, 2013 at 09:50:03AM +0000, Matt R wrote:
> I read this excellent blog article on natural transformations[1], which
> helped me gain one intuition as to what they are: "functions that don't
> make too many assumptions about their arguments". In the article, natural
> transformations make "no assumptions at all" about their arguments.
> However, it's often the case that a Haskell function will require a type
> argument constrained by a type class, e.g. show :: Show a => a -> String. I
> wondered if it was possible to characterise these functions using category
> theory too. Below is my attempt, and I'm hoping people can tell me whether
> I'm in the right ballpark (or point me in the direction of a better
> ball-park...)
>
> For a particular type class T, we can form a subcategory Hask_T of Hask
> consisting of all the instances of the type class as objects, with the
> arrows just those functions that "commute" with the signature of the type
> class. For example, in Hask_Show, the arrows would be all the functions f:
> A -> B such that:
>
> show == show . f
>
> Or for Data.Monoid, all the monoid homomorphisms f:
>
> mappend (f x) (f y) == f (mappend x y)
> mempty == f mempty
Sounds good so far. This seems like a reasonable definition of a
category, and an interesting one to study.
> In general, for any type class, we can formulate two functors f and g and a
> function sig :: f a -> g a that captures the operations in the type class,
> and then the condition is that:
>
> fmap f . sig == sig . fmap f.
Note that you can't always characterize a type class by a single
function like this. For example, consider
class Foo a where
bar :: Int -> a
baz :: a -> Int
There is no way to pick functors f and g such that a Foo dictionary is
equivalent to f a -> g a.
I would be willing to believe that there is something interesting to
say about those type classes which one *can* characterize in this way,
but I don't know what it might be.
> Then we have that the polymorphic functions with a type class constraint of
> T are just the same thing as natural transformations in this subcategory
> Hask_T.
This doesn't really make sense. If a natural transformation
consists of a family of arrows which all live in Hask_T, then all
those arrows must (by definition) commute with the type class
signature. But consider, for example, the function
data Foo = Foo | Bar -- no Show instance!
f :: Show a => a -> Foo
f a | show a == "woz" = Foo
| otherwise = Bar
This f certainly does not satisfy show == show . f -- that isn't
even well-typed as Foo doesn't have a Show instance; and if it did it
would be easy to make a Show instance for which that equation didn't
hold.
Interpreting a type class constraint as determining what category we
are living in is quite appealing, and I have seen this approach taken
informally especially when talking about classes such as Eq and Ord.
However, I have never seen it spelled out and I am not sure what the
right way to do it is in general.
Another approach would be to simply consider a type class constraint
equivalent to a dictionary argument, as in
Show a => a -> Foo
=== Show a -> a -> Foo
=== (a -> String) -> (a -> Foo)
which we can see as a natural transformation between the
(contravariant) functors (_ -> String) and (_ -> Foo).
-Brent
> Is the above correct / along the right lines?
>
> Thanks,
>
> -- Matt
>
> [1] "You Could Have Defined Natural Transformations",
> http://blog.sigfpe.com/2008/05/you-could-have-defined-natural.html
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 2
Date: Thu, 14 Nov 2013 21:05:41 +0100
From: Emanuel Koczwara <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] POSIX signals and deamons
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
Hi,
I'm trying to create a simple daemon with hdaemonize. The deamon runs
ok, but i'm having trouble with signals. Here is my test case:
import Control.Monad
import Control.Concurrent
import System.Posix.Syslog
import System.Posix.Signals
import System.Posix.Daemonize
main = daemonize $ do
withSyslog "my-test-daemon" [PID] DAEMON $
syslog Info "daemon started"
installHandler sigKILL (Catch killHandler) Nothing
forever $ threadDelay 1000
killHandler = withSyslog "my-test-daemon" [PID] DAEMON $ do
syslog Info "kill signal received"
When I run it:
$ ./test
$
Everything works great:
$ ps aux | grep test
emanuel 12790 2.6 0.0 6552 852 ? S 20:57 0:00 ./test
and:
# tail /var/log/daemon.log
Nov 14 20:52:06 emanuel-laptop my-test-daemon[12689]: daemon started
when I do:
$ kill -9 12790
process no longer exist:
$ ps aux | grep test
$
but/var/log/daemon.log doesn't change:
# tail /var/log/daemon.log
Nov 14 20:52:06 emanuel-laptop my-test-daemon[12689]: daemon started
It looks like my sigKILL handler isn't called, why?
Thanks,
Emanuel
------------------------------
Message: 3
Date: Thu, 14 Nov 2013 15:10:17 -0500
From: Brandon Allbery <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] POSIX signals and deamons
Message-ID:
<cakfcl4wwpogixgqa43drjt+80kya_hdhzz8x9c8ac5c8rzm...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Thu, Nov 14, 2013 at 3:05 PM, Emanuel Koczwara <[email protected]
> wrote:
> installHandler sigKILL (Catch killHandler) Nothing
>
This should really have thrown an exception, because SIGKILL cannot be
trapped, blocked, or ignored per POSIX. Maybe you want SIGTERM?
--
brandon s allbery kf8nh sine nomine associates
[email protected] [email protected]
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131114/31f0fc95/attachment-0001.html>
------------------------------
Message: 4
Date: Thu, 14 Nov 2013 21:24:06 +0100
From: Emanuel Koczwara <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] POSIX signals and deamons
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"
Hi,
W dniu 14.11.2013 21:10, Brandon Allbery pisze:
> On Thu, Nov 14, 2013 at 3:05 PM, Emanuel Koczwara
> <[email protected] <mailto:[email protected]>> wrote:
>
> installHandler sigKILL (Catch killHandler) Nothing
>
>
> This should really have thrown an exception, because SIGKILL cannot be
> trapped, blocked, or ignored per POSIX. Maybe you want SIGTERM?
You have right, sigTERM works as expected. Thank you.
Emanuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131114/0afdd9c7/attachment-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 65, Issue 7
****************************************