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: Advice on what to install (Thomas H?hn)
   2. Re:  Advice on what to install
      (Stephen Blackheath [to Haskell-Beginners])
   3. Re:  Re: Advice on what to install (Chris Saunders)
   4.  Ghci & wxhaskell (legajid)
   5. Re:  Re: Advice on what to install (Brent Yorgey)
   6. Re:  I need advice on design (Hector Guilarte)
   7. Re:  Interrupting a thread (Floptical Logic)


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

Message: 1
Date: Mon, 28 Dec 2009 21:02:47 +0100
From: Thomas H?hn <[email protected]>
Subject: [Haskell-beginners] Re: Advice on what to install
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

"Chris Saunders" <[email protected]> writes:

> I noticed the availability of Haskell Platform 
> 2009.2.0.2 and did install this and when I run GHCi it says that its version 
> is 
> 6.10.4.  Now on the GHC site I notice that the current version is 
> 6.12.  Should I have installed this more recent version or  stick with 
> what I have?  Warning: many more dumb questions to come from this 
> guy.

Stick with the Haskell Platform.

But if you don't and you actually manage to get not only GHC, but also
cabal-install (including all prerequisites) running on Windows without
much prior knowledge, make sure to write it up and tell me how to do
it.

Thomas



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

Message: 2
Date: Tue, 29 Dec 2009 09:09:53 +1300
From: "Stephen Blackheath [to Haskell-Beginners]"
        <[email protected]>
Subject: Re: [Haskell-beginners] Advice on what to install
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

Chris,

Whatever ships with the platform is usually best.  ghc-6.10 is very
stable, but ghc-6.12 has only just been released and so some libraries
on hackage don't work with it yet.  So, 6.10.4 is the best version to
use at the moment.

Welcome to the list - please ask away, and I hope you have fun learning
Haskell!


Steve

Chris Saunders wrote:
> I noticed the availability of Haskell Platform 2009.2.0.2 and did
> install this and when I run GHCi it says that its version is 6.10.4. 
> Now on the GHC site I notice that the current version is 6.12.  Should I
> have installed this more recent version or  stick with what I have? 
> Warning: many more dumb questions to come from this guy.
>  
> Regards
> Chris Saunders
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners


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

Message: 3
Date: Mon, 28 Dec 2009 15:44:31 -0500
From: "Chris Saunders" <[email protected]>
Subject: Re: [Haskell-beginners] Re: Advice on what to install
To: <[email protected]>, Thomas H?hn <[email protected]>
Message-ID: <97c70a2543874c4e8429b3b4cf8f4...@chrispc>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
        reply-type=original

All the advice I received suggests that I stick with the Haskell Platform so 
I don't think I will attempt to install GHC 6.12 or cabal.  I actually don't 
even really know what the Haskell Platform is - perhaps you could shed some 
light?

Regards
Chris Saunders

----- Original Message ----- 
From: "Thomas Hühn" <[email protected]>
To: <[email protected]>
Sent: Monday, December 28, 2009 3:02 PM
Subject: [Haskell-beginners] Re: Advice on what to install


> "Chris Saunders" <[email protected]> writes:
>
>> I noticed the availability of Haskell Platform
>> 2009.2.0.2 and did install this and when I run GHCi it says that its 
>> version is
>> 6.10.4.  Now on the GHC site I notice that the current version is
>> 6.12.  Should I have installed this more recent version or  stick with
>> what I have?  Warning: many more dumb questions to come from this
>> guy.
>
> Stick with the Haskell Platform.
>
> But if you don't and you actually manage to get not only GHC, but also
> cabal-install (including all prerequisites) running on Windows without
> much prior knowledge, make sure to write it up and tell me how to do
> it.
>
> Thomas
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners 



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

Message: 4
Date: Mon, 28 Dec 2009 23:37:53 +0100
From: legajid <[email protected]>
Subject: [Haskell-beginners] Ghci & wxhaskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hello,
i've downloaded and installed wshaskell (GUI for windows). All messages 
are ok.
Running an example program, the dll cannot be found.

Below are the messages when i type : ghci -package wx :

GHCi, version 6.10.4: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Loading package syb ... linking ... done.
Loading package array-0.2.0.0 ... linking ... done.
Loading package containers-0.2.0.1 ... linking ... done.
Loading package bytestring-0.9.1.4 ... linking ... done.
Loading package Win32-2.2.0.0 ... linking ... done.
Loading package filepath-1.1.0.2 ... linking ... done.
Loading package old-locale-1.0.0.1 ... linking ... done.
Loading package old-time-1.0.0.2 ... linking ... done.
Loading package directory-1.0.0.3 ... linking ... done.
Loading package process-1.0.1.1 ... linking ... done.
Loading package random-1.0.0.1 ... linking ... done.
Loading package haskell98 ... linking ... done.
Loading package stm-2.1.1.2 ... linking ... done.
Loading package wxcore-0.11.1.2 ...
<command line>: can't load .so/.DLL for: wxc-msw2.8.10-0.11.1.2 (addDLL: 
could not load DLL)
: wxc-msw2.8.10-0.11.1.2: Cette application n'a pas pu démarrer car la 
configuration de l'application est incorrecte. Réinstaller l'application 
pourrait résoudre ce problème. (application couldn' start because 
configuration is incorrect. Reinstall could solve this problem)

wxc-msw2.8.10-0.11.1.2.dll has been copied to windows\system32 (windows XP)

Can someone help for this installation issue?

Thanks,
Didier





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

Message: 5
Date: Mon, 28 Dec 2009 19:54:34 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Re: Advice on what to install
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Mon, Dec 28, 2009 at 03:44:31PM -0500, Chris Saunders wrote:
> All the advice I received suggests that I stick with the Haskell Platform 
> so I don't think I will attempt to install GHC 6.12 or cabal.  I actually 
> don't even really know what the Haskell Platform is - perhaps you could 
> shed some light?

The Haskell Platform is a compiler along with a blessed set of
standard libraries and tools (e.g. cabal-install) which are stable and
have all been tested to work together---all with a convenient one-step
downloader/installer.  If you didn't use the Platform then you'd have
to install all of these things yourself, separately.

-Brent


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

Message: 6
Date: Wed, 30 Dec 2009 03:58:08 +0000
From: "Hector Guilarte" <[email protected]>
Subject: Re: [Haskell-beginners] I need advice on design
To: " Amy de Buitl?ir " <[email protected]>,
        [email protected], [email protected]
Message-ID:
        
<890881128-1262145566-cardhu_decombobulator_blackberry.rim.net-11494959...@bda567.bisx.prod.on.blackberry>
        
Content-Type: text/plain; charset="Windows-1252"

Sorry for my late answer... Check this e-mail wren ng thornton sent to me (and 
the list) on Nov 5, 2009. Sorry I'm not giving you the direct address to the 
whole discusion, but I'm sending you this from my cellphone, and the e-mail 
too... The original discusion was on the haskell-cafe mailing list and the 
title was: Memory Leak - Artificial Neural Network

Also, there's a package somebody uploaded a few days ago to hackage on ann's, 
it is called: hnn-0.1, a haskell neural network library.
 
I hope this can be usefull to you.

Hector Guilarte
Here's wren ng thornton e-mail:
As a more general high-level suggestion, the most efficient way to 
implement feedforward ANNs is to treat them as matrix multiplication 
problems and use matrices/arrays rather than lists. For a three layer 
network of N, M, and O nodes we thus:
     * start with an N-wide vector of inputs
     * multiply by the N*M matrix of weights, to get an M-vector
     * map sigmoid or other activation function
     * multiply by the M*O matrix of weights for the next layer to get 
an O-vector
     * apply some interpretation (e.g. winner-take-all) to the output

There are various libraries for optimized matrix multiplication, but 
even just using an unboxed array for the matrices will make it much 
faster to traverse through things.

-----Original Message-----
From: Amy de Buitléir <[email protected]>
Date: Mon, 28 Dec 2009 17:14:53 
To: <[email protected]>
Subject: [Haskell-beginners] I need advice on design

I'm building a library of components for artificial neural networks.
I'm used to object-oriented languages, so I'm struggling a bit to
figure out how to do a good design in a functional programming
language like Haskell.

Q1: I've come up with two designs, and would appreciate any advice on
improvements and what approach to take.

===== Design #1 =====
class Neuron n where
  activate :: [Double] -> n -> Double
  train :: [Double] -> Double -> n -> n

....and then I would have instances of this typeclass. For example:

data Perceptron = Perceptron {
        weights :: [Double],
        threshold :: Double,
        learningRate :: Double
      } deriving (Show)

instance Neuron Perceptron where
  activate inputs perceptron = ...
  train inputs target perceptron = ...

The disadvantage of this approach is that I need to define and name
each instance of neuron before I can use it. I'd rather create a
neuron on-the-fly by calling a general-purpose constructor and telling
it what functions to use for activation and training. I think that
would make it easier to re-use activation and training functions in
all sorts of different combinations. So I came up with...

===== Design #2 =====
data Neuron =
    Neuron {
        weights :: [Double],
        activate :: [Double] -> Double,
        train :: [Double] -> Double -> Neuron
      }

Q2: I thought there might be some way to define a function type, but
the following doesn't work. Is there something along these lines that
would work?

type activationFunction = [Double] -> Double
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners

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

Message: 7
Date: Wed, 30 Dec 2009 18:08:39 -0600
From: Floptical Logic <[email protected]>
Subject: Re: [Haskell-beginners] Interrupting a thread
To: "Stephen Blackheath [to Haskell-Beginners]"
        <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On Sun, Dec 27, 2009 at 1:47 PM, Stephen Blackheath [to
Haskell-Beginners] <[email protected]>
wrote:
> MVars are the lowest-level operation for this kind of thing in Haskell,
> and they're very fast. Anything can be done with MVars but in some cases
> you need extra worker threads (cheap in Haskell), and you may even need
> to kill threads (which is a safe operation in Haskell).  CHP is higher
> level and designed for this sort of complexity, so you might want to
> look at that.  I'll give you the answer I know, which is a low-level
> MVar answer.
>
> I have *not* tried compiling this code.
>
>
> import Control.Concurrent
> import Control.Concurrent.MVar
> import Data.Int
> import System.Time
>
> type Microseconds = Int64
>
> getSystemTime :: IO Microseconds
> getSystemTime = do
>    (TOD sec pico) <- getClockTime
>    return $!
>        (fromIntegral sec::Int64) * 1000000 +
>        (fromIntegral pico::Int64) `div` 1000000
>
> type Stack a = [a]  -- or whatever type you want
>
> isEmpty :: Stack a -> Bool
> isEmpty [] = True
> isEmpty _ = False
>
> pop :: Stack a -> (a, Stack a)
>
> data ScheduleInput = ModifyStack (Stack -> Stack) | WaitFor Microseconds
> | Timeout
>
> never = maxBound :: Microseconds
>
> schedule :: MVar ScheduleInput -> MVar a -> Stack a -> IO ()
> schedule inpVar wnVar stack = schedule_ never stack
>  where
>    schedule_ :: Microseconds -> Stack -> IO ()
>    schedule_ timeout stack = do
>        now <- getSystemTime
>        let tillTimeout = 0 `max` (timeout - now)
>        if tillTimeout == 0 && not (isEmpty stack) then do
>            let (val, stack') = pop stack
>            putMVar wnVar (PopValue val)
>            schedule never stack'
>          else do
>            inp <- takeMVarWithTimeout (fromIntegral tillTimeout) inpVar
>            case inp of
>                ModifyStack f -> schedule_ timeout (f stack)
>                WaitFor t        -> do
>                    now <- getSystemTime
>                    schedule (t+now) stack
>                Timeout        -> schedule timeout stack
>
> readMVarWithTimeout :: Int -> MVar ScheduleInput -> IO ScheduleInput
> readMVar timeoutUS inpVar = do
>    tid <- forkIO $ do
>        threadDelay timeoutUS
>        putMVar inpVar Timeout
>    inp <- takeMVar inpVar
>    killThread tid
>    return inp
>
> waitNotify :: MVar ScheduleInput -> MVar Int -> IO ()
> waitNotify schInp wnInp = do
>    val <- takeMVar wnInp
>    ...notify...
>    let t = ....
>    putMVar schInp $ WaitFor t  -- block input for the specified period
>
> main = do
>    schVar <- newEmptyMVar
>    wnVar <- newEmptyMVar
>    forkIO $ schedule schVar wnVar []
>    forkIO $ waitNotify wnVar schVar
>    ...
>    -- Modify stack according to user input inside your main IO loop
>    putMVar schVar $ ModifyStack $ \stack -> ...
>
>
> I'm sure this is not exactly what you want, but at least it illustrates
> how you can achieve anything you like by using MVars + extra worker
> threads + killing threads (useful for implementing timeouts).
>
>
> Steve
>
> Floptical Logic wrote:
>> Hi,
>>
>> I am new to concurrency in Haskell and I am having trouble
>> implementing the notion of interrupting a thread.
>>
>> In a new thread, call it waitNotify, I am trying to do the following:
>> pop a number from a stack, wait some number of seconds based on the
>> number popped from the stack, perform some notification, and repeat
>> until there are no more numbers in the stack at which point we wait
>> for a new number.
>>
>> These numbers will be supplied interactively by the user from main.
>> When the user supplies a new number, I want to interrupt whatever
>> waiting is happening in waitNotify, insert the number in the proper
>> position in the current stack, and resume waitNotify using the updated
>> stack.  Note, here "stack" is just a generalization; it will likely
>> just be a list.
>>
>> What is the most idiomatic way to capture this sort of behavior in
>> Haskell?  My two challenges are the notion of interrupting a thread,
>> and sharing and updating this stack between threads (main and
>> waitNotify).
>>
>> Thank you
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>

Thanks Stephen.  That worked and things are starting to make more
sense.  The crux of it all was the readMVarWithTimeout function which
does exactly what I want.

Now I want to extend this a bit further to use StateT.  I've modified
the schedule function quite a bit, and now it has type schedule ::
StateT MyState IO.  I keep the MVar actVar in MyState as well the list
(stack) of wait times.  However, the type of forkIO is forkIO :: IO ()
-> IO ThreadId.  How do I fork a new thread for schedule even though
it is wrapped in the State monad?

Thanks again.


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

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


End of Beginners Digest, Vol 18, Issue 30
*****************************************

Reply via email to