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.  [Haskell-beginers] mutex monad (Sergey Mironov)
   2. Re:  [Haskell-beginers] mutex monad (Michael Peternell)
   3.  Q 1 of 2: How stable is Haskell? (Gan Uesli Starling)
   4.  Q 2 of 2: GUI and turnkey compiler? (Gan Uesli Starling)
   5. Re:  Q 1 of 2: How stable is Haskell? (Mateusz Kowalczyk)
   6. Re:  [Haskell-beginers] mutex monad (Sergey Mironov)
   7. Re:  Q 2 of 2: GUI and turnkey compiler? (Hans Georg Schaathun)
   8. Re:  Q 1 of 2: How stable is Haskell? (Hans Georg Schaathun)


----------------------------------------------------------------------

Message: 1
Date: Fri, 31 May 2013 00:05:04 +0400
From: Sergey Mironov <[email protected]>
Subject: [Haskell-beginners] [Haskell-beginers] mutex monad
To: [email protected]
Message-ID:
        <CAD+npno9ck6xvssTQz1czbY65=vOd=+1smjyvtntyn0f1mp...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hi, cafe. Imagine that we are writing an operating system FooOS which
uses spinlocks (mutexes, critical sections) to guard shared resources
and we want the typesystem to prevent application from re-locking the
spinlock which have already been locked by the current thread. Below
is the code which does it by explicitly defining MonadSpinlockLess
class. Unfortunately, it requires tons of boilerplate instances
because we need _any_ monad except SpinlockT to be an instance of
MonadSpinlockLess. Is there a better way of doing it? Maybe GADTs?

Basically, it would be sufficient to rewrite lock function as

lock :: (! MonadSpinlock m) => Spinlock -> SpinlockT m a -> m a

but afaik we can't use negations on a typelevel, can we?


Thanks,
Sergey

---


{-# LANGUAGE GeneralizedNewtypeDeriving  #-}

import Data.IORef

newtype Spinlock = SL (IORef Int)

newtype SpinlockT m a = SpinlockT { unSpinlock :: m a }
  deriving(Monad)

class (Monad m) => MonadSpinlockLess m
instance MonadSpinlockLess IO
instance MonadSpinlockLess m => MonadSpinlockLess (ReaderT r m)
instance MonadSpinlockLess m => MonadSpinlockLess (WriterT r m)
instance MonadSpinlockLess m => MonadSpinlockLess (StateT s m)
-- .... lots of instances

class (Monad m) => MonadSpinlock m
instance Monad m => MonadSpinlock (SpinlockT m)

lock :: (MonadSpinlockLess m) => Spinlock -> SpinlockT m a -> m a
lock (SL r) h = {- atomicModifyIORef (+1) r (doesn't matter)  >> -} unSpinlock h

process :: Spinlock -> IO ()
process sl = handler_a where

  handler_a = do
    lock sl handler_b

  handler_b = do
    lock sl handler_c
    {- ^^^^ Second lock, should fail to typecheck -}

  handler_c = do
    {- do something -}
    return ()



------------------------------

Message: 2
Date: Thu, 30 May 2013 23:25:28 +0200
From: Michael Peternell <[email protected]>
Subject: Re: [Haskell-beginners] [Haskell-beginers] mutex monad
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=us-ascii

maybe you just want to use a recursive lock?

http://en.wikipedia.org/wiki/Reentrant_mutex

The approach you describe will not work, even if you would find a way to use 
negations on a typelevel. Just find a realistic example of how you would use 
such a mutex and you will see... It's not possible to know at compile time 
which call to lock() is the first and which call to lock is a subsequent call 
on the same thread. If it were, there would be no need to use recursive locking 
in the first place.

Am 30.05.2013 um 22:05 schrieb Sergey Mironov <[email protected]>:

> Hi, cafe. Imagine that we are writing an operating system FooOS which
> uses spinlocks (mutexes, critical sections) to guard shared resources
> and we want the typesystem to prevent application from re-locking the
> spinlock which have already been locked by the current thread. Below
> is the code which does it by explicitly defining MonadSpinlockLess
> class. Unfortunately, it requires tons of boilerplate instances
> because we need _any_ monad except SpinlockT to be an instance of
> MonadSpinlockLess. Is there a better way of doing it? Maybe GADTs?
> 
> Basically, it would be sufficient to rewrite lock function as
> 
> lock :: (! MonadSpinlock m) => Spinlock -> SpinlockT m a -> m a
> 
> but afaik we can't use negations on a typelevel, can we?
> 
> 
> Thanks,
> Sergey
> 
> ---
> 
> 
> {-# LANGUAGE GeneralizedNewtypeDeriving  #-}
> 
> import Data.IORef
> 
> newtype Spinlock = SL (IORef Int)
> 
> newtype SpinlockT m a = SpinlockT { unSpinlock :: m a }
>  deriving(Monad)
> 
> class (Monad m) => MonadSpinlockLess m
> instance MonadSpinlockLess IO
> instance MonadSpinlockLess m => MonadSpinlockLess (ReaderT r m)
> instance MonadSpinlockLess m => MonadSpinlockLess (WriterT r m)
> instance MonadSpinlockLess m => MonadSpinlockLess (StateT s m)
> -- .... lots of instances
> 
> class (Monad m) => MonadSpinlock m
> instance Monad m => MonadSpinlock (SpinlockT m)
> 
> lock :: (MonadSpinlockLess m) => Spinlock -> SpinlockT m a -> m a
> lock (SL r) h = {- atomicModifyIORef (+1) r (doesn't matter)  >> -} 
> unSpinlock h
> 
> process :: Spinlock -> IO ()
> process sl = handler_a where
> 
>  handler_a = do
>    lock sl handler_b
> 
>  handler_b = do
>    lock sl handler_c
>    {- ^^^^ Second lock, should fail to typecheck -}
> 
>  handler_c = do
>    {- do something -}
>    return ()
> 
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners




------------------------------

Message: 3
Date: Thu, 30 May 2013 18:50:15 -0400
From: Gan Uesli Starling <[email protected]>
Subject: [Haskell-beginners] Q 1 of 2: How stable is Haskell?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

As compared against Python and Perl, how stable is Haskell?

That is to say, between Python's 3 and 2 being so different, you pretty 
much need to know both. And with Perl 6 being "on the way" for so very 
long, and it too being a turnabout in many ways from Perl 5, it is 
discouraging to be keeping on with Perl 5 the way I've been doing.

All that said, I know that they model the forthcoming Perl 6 in Haskell, 
which is how I heard of it. And ever since then, I've been thinking if I 
were to take up a new language, Haskell had maybe ought be the one.



------------------------------

Message: 4
Date: Thu, 30 May 2013 18:54:54 -0400
From: Gan Uesli Starling <[email protected]>
Subject: [Haskell-beginners] Q 2 of 2: GUI and turnkey compiler?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Perl and Python both have GUI interfaces, which are handy for publishing 
little give-away apps, as I used to do quite a lot in Perl/Tk and also 
in ancient of days on JForth. Also to make give-away apps, there needs 
to be a turn-key compiler, something into which I'd feed code and out 
would come an *.exe (albeit quite bloated in size) that ran on any PC 
which did not have Haskell already installed.

So, are there such things also for Haskell? A GUI and a means to issue 
stand-alone apps?



------------------------------

Message: 5
Date: Fri, 31 May 2013 00:23:00 +0100
From: Mateusz Kowalczyk <[email protected]>
Subject: Re: [Haskell-beginners] Q 1 of 2: How stable is Haskell?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 30/05/13 23:50, Gan Uesli Starling wrote:
> As compared against Python and Perl, how stable is Haskell?
> 
> That is to say, between Python's 3 and 2 being so different, you
> pretty much need to know both. And with Perl 6 being "on the way"
> for so very long, and it too being a turnabout in many ways from
> Perl 5, it is discouraging to be keeping on with Perl 5 the way
> I've been doing.
> 
> All that said, I know that they model the forthcoming Perl 6 in
> Haskell, which is how I heard of it. And ever since then, I've been
> thinking if I were to take up a new language, Haskell had maybe
> ought be the one.
> 
> _______________________________________________ Beginners mailing
> list [email protected] 
> http://www.haskell.org/mailman/listinfo/beginners
> 
I think you're actually asking ``how much does Haskell change between
revisions'' and not how stable it is. If you're looking for a language
where your program will work with a compiler that's 5 years old or 5
years from now, this probably isn't it. It's not like programs break
daily because of the changes but I believe there is no hesitation to
change stuff because some program from 5 years ago might no longer
compile.

- -- 
Mateusz K.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)

iQIcBAEBAgAGBQJRp99TAAoJEM1mucMq2pqXiksP/RAcI0HG/cI78reBd87xe3S5
wpbYV110KGZb0uBM0uJQbY8iAr2BU/TluOPQrkIcJpttwfM+RUZIn4tU0wlsSQOJ
/kIYcXpjnj0X7h2PnZOaJnu7FkRMXsLYhn4UHcrR6K3Gp1gaFcgULYBiTO5Tc3Pr
ouh5uz7DrHgXyBAHLyD4MLO07TlK0IcHYIocqaYHBCYn1nznDu89Avrz+PWRvw+S
/hTpgPq3gb/sVNA/ZdRFmKmcgtp+mReETlhNMqP1vs2pqwkQoiB+K6bPNRhHuRrk
EHYHcn5kM/7chU3Lr93KTB+TTw5MDH8W/qrEUibDL5pxZyvtO9ZKQXMwqbrGiHEi
9xyXfOQ38RvriDBWEXxTmkobAZQiWx5yKLzEzdtu3QGCPFxLduaVYzQf/4KG9jQR
TegzFk06yGSL2b8dfH/vkN4L6vMx92lU9hVosWl4BTIj4ZjO8xH7kgwpRbebCcw9
FF86d2lQ9s3rqbpM+hSxF8DGk+YIKfc85gZZuFAsPqnXu5FSFfLnxsHUS6Cd0si9
wTTuPhzsfXKk3FQgnbfY/kUnv5fqJABY0Ab4rwq9pWLnrtueu7Fu42q3SwMBniHN
cuSQWqne0+K3WHupkLfkWJKH8qv8ER9yVt8wZ2pH5DGOIOl4zY+N/BFLdpbFjOn1
j3STv2ZXecSom/d9dfKs
=ZblG
-----END PGP SIGNATURE-----



------------------------------

Message: 6
Date: Fri, 31 May 2013 10:39:38 +0400
From: Sergey Mironov <[email protected]>
Subject: Re: [Haskell-beginners] [Haskell-beginers] mutex monad
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Message-ID:
        <CAD+npnq=FVy-==vaevnywakeqn+yyq6kcgrbqww7kqbhhnz...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hi. No, it is not a practical question, I am just curious.. The idea
of my code example was to upgrade "normal" non-reentrant spinlock with
a lock function which helps user to avoid re-locking in same thread.

By the way, looks like I didn't express it correctly. lock function
should actually be named withLock and it's use pattern will be

main = do
   withLock sl $ do
    liftIO $ putStrLn "sl is locked now, we are in spinlock monad"

  withLock sl2 $ do
    liftIO $ putStrLn "sl2 is locked now, we are in spinlock monad"

in other words, what I want is to place some kind of mark on a
typelevel saying that lock is being held.

Thanks,
Sergey

2013/5/31 Michael Peternell <[email protected]>:
> maybe you just want to use a recursive lock?
>
> http://en.wikipedia.org/wiki/Reentrant_mutex
>
> The approach you describe will not work, even if you would find a way to use 
> negations on a typelevel. Just find a realistic example of how you would use 
> such a mutex and you will see... It's not possible to know at compile time 
> which call to lock() is the first and which call to lock is a subsequent call 
> on the same thread. If it were, there would be no need to use recursive 
> locking in the first place.
>
> Am 30.05.2013 um 22:05 schrieb Sergey Mironov <[email protected]>:
>
>> Hi, cafe. Imagine that we are writing an operating system FooOS which
>> uses spinlocks (mutexes, critical sections) to guard shared resources
>> and we want the typesystem to prevent application from re-locking the
>> spinlock which have already been locked by the current thread. Below
>> is the code which does it by explicitly defining MonadSpinlockLess
>> class. Unfortunately, it requires tons of boilerplate instances
>> because we need _any_ monad except SpinlockT to be an instance of
>> MonadSpinlockLess. Is there a better way of doing it? Maybe GADTs?
>>
>> Basically, it would be sufficient to rewrite lock function as
>>
>> lock :: (! MonadSpinlock m) => Spinlock -> SpinlockT m a -> m a
>>
>> but afaik we can't use negations on a typelevel, can we?
>>
>>
>> Thanks,
>> Sergey
>>
>> ---
>>
>>
>> {-# LANGUAGE GeneralizedNewtypeDeriving  #-}
>>
>> import Data.IORef
>>
>> newtype Spinlock = SL (IORef Int)
>>
>> newtype SpinlockT m a = SpinlockT { unSpinlock :: m a }
>>  deriving(Monad)
>>
>> class (Monad m) => MonadSpinlockLess m
>> instance MonadSpinlockLess IO
>> instance MonadSpinlockLess m => MonadSpinlockLess (ReaderT r m)
>> instance MonadSpinlockLess m => MonadSpinlockLess (WriterT r m)
>> instance MonadSpinlockLess m => MonadSpinlockLess (StateT s m)
>> -- .... lots of instances
>>
>> class (Monad m) => MonadSpinlock m
>> instance Monad m => MonadSpinlock (SpinlockT m)
>>
>> lock :: (MonadSpinlockLess m) => Spinlock -> SpinlockT m a -> m a
>> lock (SL r) h = {- atomicModifyIORef (+1) r (doesn't matter)  >> -} 
>> unSpinlock h
>>
>> process :: Spinlock -> IO ()
>> process sl = handler_a where
>>
>>  handler_a = do
>>    lock sl handler_b
>>
>>  handler_b = do
>>    lock sl handler_c
>>    {- ^^^^ Second lock, should fail to typecheck -}
>>
>>  handler_c = do
>>    {- do something -}
>>    return ()
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners



------------------------------

Message: 7
Date: Fri, 31 May 2013 07:58:48 +0100
From: Hans Georg Schaathun <[email protected]>
Subject: Re: [Haskell-beginners] Q 2 of 2: GUI and turnkey compiler?
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=us-ascii

On Thu, May 30, 2013 at 06:54:54PM -0400, Gan Uesli Starling wrote:
> Perl and Python both have GUI interfaces, which are handy for
> publishing little give-away apps, as I used to do quite a lot in
> Perl/Tk and also in ancient of days on JForth.

Do you mean a GUI library?  Or a GUI interface to the interpreter?

There are plenty of GUI libraries.  _Real World Haskell_ from
O'Reilly presents one approach, and is otherwise a good read at
http://book.realworldhaskell.org

>                                                Also to make
> give-away apps, there needs to be a turn-key compiler,

The glasgow haskell compiler (ghc) is a compiler.

>                                                        something
> into which I'd feed code and out would come an *.exe (albeit quite
> bloated in size)

well, you can always rename the file to *.exe or whatever else you
want.  I cannot see how that's relevant.

-- 
:-- Hans Georg



------------------------------

Message: 8
Date: Fri, 31 May 2013 07:59:11 +0100
From: Hans Georg Schaathun <[email protected]>
Subject: Re: [Haskell-beginners] Q 1 of 2: How stable is Haskell?
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=us-ascii

> On 30/05/13 23:50, Gan Uesli Starling wrote:
> > As compared against Python and Perl, how stable is Haskell?

I must say, I find the comparison odd.  The transition from
imperative to declarative programming must be much more mind-bogging
than figuring out how to deal with instability.  Surely, there
are both more and less stable options within each paradigm.

On Fri, May 31, 2013 at 12:23:00AM +0100, Mateusz Kowalczyk wrote:
> I think you're actually asking ``how much does Haskell change between
> revisions'' and not how stable it is. If you're looking for a language
> where your program will work with a compiler that's 5 years old or 5
> years from now, this probably isn't it. It's not like programs break
> daily because of the changes but I believe there is no hesitation to
> change stuff because some program from 5 years ago might no longer
> compile.

It may be useful to distinguish between stability of the language and
stability of the libraries.  Talking about libraries, you are probably
right.

In fact, I have tried to install a number of libraries from hackage
recently, and only about half of them succeeded.  The typical problem
with the others seem to be changes in their dependencies.  Typical
age is about 3-6 years, I think.

Python however, is not even stable in terms of core language.

Although library evolution can also break your program, such 
breakage is generally easier to repair.

The problem for haskell, of course, is that the community is
too small to sustain a standard library of the extent seen for
python or java.  Hence one relies much more on beta versions
and stale libraries.  That does not make haskell any less stable;
it is a very different kind of problem.

-- 
:-- Hans Georg



------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 59, Issue 42
*****************************************

Reply via email to