Re: [Haskell-cafe] Instantiation problem

2011-01-31 Thread Tom Nielsen
Patrick,

I find Andrew Frank's work on axiomatic specifications of GIS systems
-- which the paper you cite is built on -- very confusing, or indeed,
confused. They have a bunch of example like

data Car = Car Color

class Car a where
   carColor :: a - Color

instance Car Car where
   carColor (Car c _) = c

as if there is some kind of special logical interpretation of having a
class Car in addition to the data type Car. As far as I remember, they
interpret type classes as axioms. After reading it, without being an
expert in either GIS or a logician, I came away thinking that they
were mixing some very abstract ideas from object-oriented languages
into Haskell. I find the presentations of type classes by e.g. Mark
Jones, and the links between functional programming and logic from
either the Curry-Howard correspondence or HOL-style reasoning (for
instance, see the HOL light manual), somewhat crisper.

Tom

On Sun, Jan 30, 2011 at 10:27 AM, Patrick Browne patrick.bro...@dit.ie wrote:
 On 29/01/2011 20:56, Henning Thielemann wrote:
 Is there a reason why you use an individual type for every unit?
 The existing implementations of typed physical units only encode the
 physical dimension in types and leave the unit factors to the value
 level. I found this to be the most natural way.

 I am studying type classes using examples from the literature [1].
 There is no particular intension to implement anything.

 I am confused about the unit function in the code below.
 My understanding is:
 The signature of the unit function is defined in the MetricDescription
 class.
 Any valid instantce of MetricDescription will respect the functional
 dependency (FD):
 The FD | description - unit  is exactly the signature of the unit function.

 My confusions
 I do not understand the definitions of unit in the instances.
 I do not know how the constant 1 can be equated with a *type*, Where did
 1 come from?
 I do not know how the constant 1 can be equated with *two distinct*
 definitions of the function uint and still produce the following correct
 results

 Ok, modules loaded: A.
 *A  unit (LengthInMetres  7)
 Metre
 *A unit (LengthInCentimetres 7)
 Centimetre
 *A



 [1] http://ifgi.uni-muenster.de/~lutzm/odbase04_schade_et_al.pdf

 ==

 module A where

 -- Each member of the Unit class has one operator convertFactorToBaseUnit
 -- that takes a measurement unit (say metre) and returns a conversion
 factor for that unit of measurement
 class  Unit unit where
  convertFactorToBaseUnit :: unit - Double



 class (Unit unit) = MetricDescription description unit | description -
 unit where
  unit :: description - unit
  valueInUnit :: description - Double
  valueInBaseUnit :: description - Double
  valueInBaseUnit d = (convertFactorToBaseUnit(unit d)) * (valueInUnit d)

 data Dog = Dog  deriving Show
 data Metre = Metre  deriving Show
 data Centimetre = Centimetre deriving Show


 -- An instance for metres, where the convert factor is 1.0
 instance Unit Metre where
  convertFactorToBaseUnit Metre  = 1.0

 -- An instance for centimetres, where the convert factor is 0.1
 instance Unit Centimetre where
  convertFactorToBaseUnit Centimetre  = 0.1



 data LengthInMetres = LengthInMetres Double  deriving Show
 data LengthInCentimetres = LengthInCentimetres Double  deriving Show

 instance MetricDescription LengthInMetres Metre where
  valueInUnit (LengthInMetres d) = d
  unit l = Metre



 instance MetricDescription LengthInCentimetres Centimetre where
  valueInUnit (LengthInCentimetres d) = d
  unit l = Centimetre


 This message has been scanned for content and viruses by the DIT Information 
 Services E-Mail Scanning Service, and is believed to be clean. 
 http://www.dit.ie

 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Cabal ignores ld-options? - 2011 remix

2011-01-31 Thread Duncan Coutts
On Mon, 2011-01-31 at 01:13 -0500, Ryan Newton wrote:
 Ok, I've made some progress in the direction Duncan suggested.
 
 I can filter out the extra library before the postConf hook gets it.
 And calling make from the hooks is pretty easy.
 
 I've got a hack working that does allow full build/link/install given
 a hardcoded path (e.g. hack).  It works by passing -Wl,-rpath=/opt/...
 directly through the .cabal file (ld-options).  I need to un-hardcode
 that directory but I can't figure out how to achieve the same effect
 as that ld-options from my Setup.hs (I tried adding buildProgramArgs
 in the buildHook but no luck yet).

Just modify the package description instead, e.g. in the configure step.
The build prog args is intended for users, not for package authors. 

(It's so that cabal build --$PROG-options= works, and that's not
something you're supposed to interfere with. Afterall, users are in
control and can always add whatever options they want by adding wrapper
scripts etc, this just makes it more convenient.)

 There's also the question of how to find the install dir so that rpath
 can be set to it.  Unfortunately, I haven't been able to dig that out
 yet.  When I try to use absoluteInstallDirs via something like below,
 I get this error: setup: internal error InstallDirs.libsubdir
 
   putStrLn$ Install dirs:  ++ show (absoluteInstallDirs desc linfo
 NoCopyDest)

You're doing the right thing, just don't look at the libsubdir or
datasubdir after calling absoluteInstallDirs, because those do not make
sense after making the paths absolute (they're inherently relative).

The reason it's labelled as an internal error is because if cabal were
ever to call those, then it would be an internal error. When you call it
however, it's your fault ;-)

Duncan


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANNOUNCE: genprog-0.1

2011-01-31 Thread grzegorz.nowak

Jan,

great, great work.

Although I'm quite new to the Haskell (but experienced in a dozen of
imperative languages and GP), I had no difficulties with adopting your
example to my initial needs.
Now I'm facing new problem: is it possible to create recursive program
structures with your library (or using Haskell itself), so that you could
simulate loop-like structures in the code  ?
Sorry if the answer to this question is obvious - I'm still getting used to
the Haskell -)

Thanks a lot for sharing this and congratulations. 
keep posting!
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/Re-ANNOUNCE-genprog-0-1-tp3310770p3364371.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Yesod and concurrency

2011-01-31 Thread Ertugrul Soeylemez
Michael Snoyman mich...@snoyman.com wrote:

 On Mon, Jan 31, 2011 at 1:09 PM, Ertugrul Soeylemez e...@ertes.de wrote:
  Hello everybody,
 
  how well do WAI, Yesod and the 'persistent' package play with
  concurrency?  For example, I'd like to write a program, which
  concurrently provides two related sites as well as a few background
  workers, which do something with the database.  My idea would look
  something like this:
 
   main :: IO ()
   main =
     withMyAppPool $ \pool - do
       forkIO $ worker1 ...   -- background worker
       forkIO $ worker2 ...   -- background worker
       forkIO $ worker3 ...   -- background worker
       forkIO $ toWaiApp ...  -- site 1
       forkIO $ toWaiApp ...  -- site 2
 
  Will I run into problems with this?

 There should not be any issues, just make sure you compile with
 -threaded. The persistent database connection pool should work just
 fine for this. If you find any issues, please let me know, but I have
 not had trouble in the past.

Thank you for your quick reply.  How are my chances to get patches to
Yesod incorporated into the mainstream code?


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife = sex)
http://ertes.de/



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Yesod and concurrency

2011-01-31 Thread Michael Snoyman
On Mon, Jan 31, 2011 at 2:28 PM, Ertugrul Soeylemez e...@ertes.de wrote:
 Michael Snoyman mich...@snoyman.com wrote:

 On Mon, Jan 31, 2011 at 1:09 PM, Ertugrul Soeylemez e...@ertes.de wrote:
  Hello everybody,
 
  how well do WAI, Yesod and the 'persistent' package play with
  concurrency?  For example, I'd like to write a program, which
  concurrently provides two related sites as well as a few background
  workers, which do something with the database.  My idea would look
  something like this:
 
   main :: IO ()
   main =
     withMyAppPool $ \pool - do
       forkIO $ worker1 ...   -- background worker
       forkIO $ worker2 ...   -- background worker
       forkIO $ worker3 ...   -- background worker
       forkIO $ toWaiApp ...  -- site 1
       forkIO $ toWaiApp ...  -- site 2
 
  Will I run into problems with this?

 There should not be any issues, just make sure you compile with
 -threaded. The persistent database connection pool should work just
 fine for this. If you find any issues, please let me know, but I have
 not had trouble in the past.

 Thank you for your quick reply.  How are my chances to get patches to
 Yesod incorporated into the mainstream code?

If it's a clean patch and does not break backwards compatibility: very
high. If it's a clean patch that *does* break backwards compatibility:
still good, but you'll have to wait till a major release. For
not-so-clean patches, I suppose it depends on how dirty we're talking
;).

Michael

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Loading bitmap with xlib

2011-01-31 Thread Francesco Mazzoli
Francesco Mazzoli f at mazzo.li writes:

At the end I gave up and I wrote the function myself:

http://hpaste.org/43464/readbitmapfile


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] The implementation of Control.Exception.bracket

2011-01-31 Thread Leon Smith
There is a common idiom used in Control.Concurrent libraries,  as
embodied in the implementation of bracket:

http://www.haskell.org/ghc/docs/7.0-latest/html/libraries/base-4.3.0.0/src/Control-Exception-Base.html#bracket

bracket before after thing =
  mask $ \restore - do
a - before
r - restore (thing a) `onException` after a
_ - after a
return r


Is there any particular reason why bracket is not implemented as:

bracket before after thing =
  mask $ \restore - do
a - before
r - restore (thing a) `finally` after a
return r

Is there some subtle semantic difference?   Is there a performance
difference?   It seems like a trivial thing,  but I am genuinely
curious.

Best,
Leon

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] The implementation of Control.Exception.bracket

2011-01-31 Thread Max Bolingbroke
On 31 January 2011 14:17, Leon Smith leon.p.sm...@gmail.com wrote:
 Is there some subtle semantic difference?   Is there a performance
 difference?   It seems like a trivial thing,  but I am genuinely
 curious.

According to my understanding the two should have equivalent
semantics. As for performance, I whipped up a trivial Criterion
microbenchmark and the version that doesn't use finally seems to
consistently benchmark 32ns (33%) faster than the version that does
use it, likely because it avoids a useless mask/restore pair.

(Note that this result is reversed if you compile without -O2, I guess
because -O2 optimises the library finally enough to overcome the
fact that it does an extra mask).

Code in the appendix.

Cheers,
Max

===

{-# LANGUAGE Rank2Types #-}
import Control.Exception

import Criterion.Main

{-# NOINLINE bracket_no_finally #-}
bracket_no_finally :: IO a - (a - IO b) - (a - IO c) - IO c
bracket_no_finally before after thing =
 mask $ \restore - do
   a - before
   r - restore (thing a) `onException` after a
   _ - after a
   return r

{-# NOINLINE bracket_finally #-}
bracket_finally :: IO a - (a - IO b) - (a - IO c) - IO c
bracket_finally before after thing =
 mask $ \restore - do
   a - before
   r - restore (thing a) `finally` after a
   return r

{-# NOINLINE test_bracket #-}
test_bracket :: (forall a b c. IO a - (a - IO b) - (a - IO c) -
IO c) - IO ()
test_bracket bracket = bracket (return ()) (\() - return ()) (\() - return ())

main = defaultMain [
  bench finally $ test_bracket bracket_finally
, bench no finally $ test_bracket bracket_no_finally
   ]

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Typing problem

2011-01-31 Thread michael rice
I'm mapping a function over a list of data, where the mapping function is
determined from the data.

g f l = map (g l) l

So

g serialize prolog  -  [4,5,3,2,3,1]

But I'm having typing problems trying to do a similar thing with a function
that statistically normalizes data.

See:
http://people.revoledu.com/kardi/tutorial/Similarity/Normalization.html#Statistic

So

g normalize [2,5,3,2]  -  
[-0.7071067811865475,1.414213562373095,0.0,-0.7071067811865475]

Is my typing for normalize too loose. Should I be using Floating rather than 
Num?

Michael

===Code==
{-
See Problem 42, pg. 63, Prolog by Example, Coelho  Cotta

Generate a list of serial numbers for the items of a given list,
the members of which are to be numbered in alphabetical order.

*Main serialize prolog
[4,5,3,2,3,1]
*Main serialize int.artificial
[5,7,9,1,2,8,9,5,4,5,3,5,2,6]

*Main [prolog] = serialize
[4,5,3,2,3,1]
*Main [int.artificial] = serialize
[5,7,9,1,2,8,9,5,4,5,3,5,2,6]
-}

import Data.Map hiding (map)
import Data.List

{-
serialize :: [Char] - [Int]
serialize l = map (f l) l 
  where
    f = ((!) . fromList . ((flip zip) [1..]) . (sort . nub))
-}

serialize :: (Ord a, Integral b) = [a] - a - b
serialize = ((!) . fromList . ((flip zip) [1..]) . (sort . nub))

g f l = map (f l) l

normalize :: (Num a, Num b) = [a] - a - b
normalize l = let (total,len) = sumlen l
  avg = total/len
  stdev = sqrt $ ((/) (len-1)) $ sum $ map ((** 2.0) . 
(subtract avg)) l
  in  ((/) stdev) . (subtract avg) 
  
sumlen :: (Num a, Integral b) = [a] - (a,b)
sumlen l = sumlen' l 0 0
   where sumlen' [] sum len = (sum,len)
 sumlen' (h:t) sum len = sumlen' t (sum+h) (len+1)
=

Prelude :r
[1 of 1] Compiling Main ( serialize2.hs, interpreted )

serialize2.hs:34:32:
    Could not deduce (Integral a) from the context (Num a, Num b)
  arising from a use of `sumlen' at serialize2.hs:34:32-39
    Possible fix:
  add (Integral a) to the context of
    the type signature for `normalize'
    In the expression: sumlen l
    In a pattern binding: (total, len) = sumlen l
    In the expression:
    let
  (total, len) = sumlen l
  avg = total / len
  stdev = sqrt
    $   ((/) (len - 1)) $ sum $ map ((** 2.0) . (subtract avg)) l
    in (/ stdev) . (subtract avg)

serialize2.hs:36:61:
    Could not deduce (Floating a) from the context (Num a, Num b)
  arising from a use of `**' at serialize2.hs:36:61-66
    Possible fix:
  add (Floating a) to the context of
    the type signature for `normalize'
    In the first argument of `(.)', namely `(** 2.0)'
    In the first argument of `map', namely
    `((** 2.0) . (subtract avg))'
    In the second argument of `($)', namely
    `map ((** 2.0) . (subtract avg)) l'

serialize2.hs:37:18:
    Couldn't match expected type `b' against inferred type `a'
  `b' is a rigid type variable bound by
  the type signature for `normalize' at serialize2.hs:33:25
  `a' is a rigid type variable bound by
  the type signature for `normalize' at serialize2.hs:33:18
    In the expression: (/ stdev) . (subtract avg)
    In the expression:
    let
  (total, len) = sumlen l
  avg = total / len
  stdev = sqrt
    $   ((/) (len - 1)) $ sum $ map ((** 2.0) . (subtract avg)) l
    in (/ stdev) . (subtract avg)
    In the definition of `normalize':
    normalize l = let
    (total, len) = sumlen l
    avg = total / len
    
  in (/ stdev) . (subtract avg)
Failed, modules loaded: none.




  ___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Typing problem

2011-01-31 Thread Daniel Fischer
On Monday 31 January 2011 18:29:59, michael rice wrote:
 I'm mapping a function over a list of data, where the mapping function
 is determined from the data.

 g f l = map (g l) l

g f l = map (f l) l

probably


 So

 g serialize prolog  -  [4,5,3,2,3,1]

 But I'm having typing problems trying to do a similar thing with a
 function that statistically normalizes data.

 See:
 http://people.revoledu.com/kardi/tutorial/Similarity/Normalization.html#
Statistic

 So

 g normalize [2,5,3,2]  - 
 [-0.7071067811865475,1.414213562373095,0.0,-0.7071067811865475]

 Is my typing for normalize too loose.

You can omit the type signatures and see what the compiler infers as the 
type. In this case, 


 normalize :: (Num a, Num b) = [a] - a - b
 normalize l = let (total,len) = sumlen l
   avg = total/len
   stdev = sqrt $ ((/) (len-1)) $ sum $ map ((** 2.0) .
 (subtract avg)) l in  ((/) stdev) . (subtract avg)

In the final result, I suppose it should be (/ stdev) and not ((/) stdev) 
[the latter is (stdev /), i.e. \x - stdev / x].

by sumlen's type, len has an Integral type. You want to use (/) to divide, 
which gives a Fractional constraint,

(/) :: Fractional a = a - a - a

Since it is not sensible for a type to be a member of both, the Fractional 
and Integral classes, you should convert len to the appropriate type with 
fromIntegral. For stdev, you call

sqrt :: Floating a = a - a
and
(**) :: Floating a = a - a

which means the list elements must have a type belonging to Floating
(you could replace the (** 2.0) with (^ 2), which would probably be better, 
but the Floating constraint remains due to the sqrt).
Finally, the resulting function is \x - (x - avg) / stdev, hence x must 
have the same type as abg and stdev, and the final result has the same 
type. Altogether,

normalize :: Floating a = [a] - a - a
normalize l =
  let (total, len0) = sumlen l
  len = fromIntegral len0
  avg = total/len
  stdev = sqrt $ sum [(x-avg)^2 | x - l] / (len-1)
  in (/ stdev) . subtract avg

but that gives nonsense if you pass a complex-valued list, so it might be 
better to restrict the type to

normalize :: RealFloat a = [a] - a - a

 Should I be using Floating rather than Num?

You have to, and one number type only (well, you could use two or three 
types if you compose with conversion functions, realToFrac for example).


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Typing problem

2011-01-31 Thread Steffen Schuldenzucker


Michael,

just leaving out the type declaration for 'normalize', your module 
complies fine and ghc infers the following type:


normalize :: (Integral a, Floating a) = [a] - a - a

Note that the context (Integral a, Floating a) cannot be met by any of 
the standard types. (try in ghci: :i Integral and :i Floating)
So we have to apply a conversion function like this: (I just replaced 
len by len' at all occurrences)


 normalize l = let (total,len) = sumlen l
  len' = fromIntegral len
  avg = total/len'
  stdev = sqrt $ ((/) (len'-1)) $ sum $ map ((** 2.0) 
. (subtract avg)) l

  in  ((/) stdev) . (subtract avg)

yielding a type of

normalize :: (Floating b) = [b] - b - b

You could save the conversion by allowing a more liberal type for 
'sumlen'. Without the type signature, it is inferred to


sumlen :: (Num t, Num t1) = [t] - (t, t1)

-- Steffen

On 01/31/2011 06:29 PM, michael rice wrote:

I'm mapping a function over a list of data, where the mapping function is
determined from the data.

g f l = map (g l) l

So

g serialize prolog  -  [4,5,3,2,3,1]

But I'm having typing problems trying to do a similar thing with a 
function

that statistically normalizes data.

See:
http://people.revoledu.com/kardi/tutorial/Similarity/Normalization.html#Statistic

So

g normalize [2,5,3,2]  -  
[-0.7071067811865475,1.414213562373095,0.0,-0.7071067811865475]


Is my typing for normalize too loose. Should I be using Floating 
rather than Num?


Michael

===Code==
{-
See Problem 42, pg. 63, Prolog by Example, Coelho  Cotta

Generate a list of serial numbers for the items of a given list,
the members of which are to be numbered in alphabetical order.

*Main serialize prolog
[4,5,3,2,3,1]
*Main serialize int.artificial
[5,7,9,1,2,8,9,5,4,5,3,5,2,6]

*Main [prolog] = serialize
[4,5,3,2,3,1]
*Main [int.artificial] = serialize
[5,7,9,1,2,8,9,5,4,5,3,5,2,6]
-}

import Data.Map hiding (map)
import Data.List

{-
serialize :: [Char] - [Int]
serialize l = map (f l) l
  where
f = ((!) . fromList . ((flip zip) [1..]) . (sort . nub))
-}

serialize :: (Ord a, Integral b) = [a] - a - b
serialize = ((!) . fromList . ((flip zip) [1..]) . (sort . nub))

g f l = map (f l) l

normalize :: (Num a, Num b) = [a] - a - b
normalize l = let (total,len) = sumlen l
  avg = total/len
  stdev = sqrt $ ((/) (len-1)) $ sum $ map ((** 2.0) . 
(subtract avg)) l

  in  ((/) stdev) . (subtract avg)

sumlen :: (Num a, Integral b) = [a] - (a,b)
sumlen l = sumlen' l 0 0
   where sumlen' [] sum len = (sum,len)
 sumlen' (h:t) sum len = sumlen' t (sum+h) (len+1)
=

Prelude :r
[1 of 1] Compiling Main ( serialize2.hs, interpreted )

serialize2.hs:34:32:
Could not deduce (Integral a) from the context (Num a, Num b)
  arising from a use of `sumlen' at serialize2.hs:34:32-39
Possible fix:
  add (Integral a) to the context of
the type signature for `normalize'
In the expression: sumlen l
In a pattern binding: (total, len) = sumlen l
In the expression:
let
  (total, len) = sumlen l
  avg = total / len
  stdev = sqrt
$   ((/) (len - 1)) $ sum $ map ((** 2.0) . (subtract 
avg)) l

in (/ stdev) . (subtract avg)

serialize2.hs:36:61:
Could not deduce (Floating a) from the context (Num a, Num b)
  arising from a use of `**' at serialize2.hs:36:61-66
Possible fix:
  add (Floating a) to the context of
the type signature for `normalize'
In the first argument of `(.)', namely `(** 2.0)'
In the first argument of `map', namely
`((** 2.0) . (subtract avg))'
In the second argument of `($)', namely
`map ((** 2.0) . (subtract avg)) l'

serialize2.hs:37:18:
Couldn't match expected type `b' against inferred type `a'
  `b' is a rigid type variable bound by
  the type signature for `normalize' at serialize2.hs:33:25
  `a' is a rigid type variable bound by
  the type signature for `normalize' at serialize2.hs:33:18
In the expression: (/ stdev) . (subtract avg)
In the expression:
let
  (total, len) = sumlen l
  avg = total / len
  stdev = sqrt
$   ((/) (len - 1)) $ sum $ map ((** 2.0) . (subtract 
avg)) l

in (/ stdev) . (subtract avg)
In the definition of `normalize':
normalize l = let
(total, len) = sumlen l
avg = total / len

  in (/ stdev) . (subtract avg)
Failed, modules loaded: none.



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
   


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org

Re: [Haskell-cafe] Haskell for children? Any experience?

2011-01-31 Thread Tim Chevalier
On Thu, Jan 27, 2011 at 7:28 AM, aditya siram aditya.si...@gmail.com wrote:
 Ye gods! A B  D [1] language for kids? At least give them a fighting
 chance [2] at becoming future developers.

 Haskell's immutability is good for mathematics but doing anything else
 takes a great deal of up-front patience and perseverance, two very
 rare qualities in that demographic if my own childhood is any
 indication.

 BTW I want to be wrong so if you do succeed with this I will feast on
 crow with gusto.


IMO, the two very rare qualities part is a self-fulfilling prophecy.
Didn't a lot of us spend endless hours tinkering with Linux
configurations or seeing how many ways there were to use the debugger
to make the computer crash when we were teenagers (if we were lucky
enough to have computers as teenagers, anyway)? Kids -- and other
people -- do amazing things when no one tells them it's hard.

To the OP, I think teaching Haskell to 11-13 year olds should if
anything be easier than teaching it to undergrads. At that age,
they're less likely to have absorbed social math is hard messages
and less likely to have absorbed Real-Programmer-ish ideas about what
languages they're supposed to be programming in or what languages are
practical. Sounds like a joy! Also, if you haven't, check out the book
_Mindstorms_ by Seymour Papert -- the particular programming paradigm
he advocates is different, but there should be some good fundamental
ideas to inspire you.

Cheers,
Tim


-- 
Tim Chevalier * http://cs.pdx.edu/~tjc/ * Often in error, never in doubt
an intelligent person fights for lost causes,realizing that others
are merely effects -- E.E. Cummings

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell WalkSat algorithm implementation

2011-01-31 Thread Manolache Andrei-Ionut
I need some help if possible with the following problem.The WalkSat 
algorithm takes a formula, a probability 0 = p = 1, and a 
boundary of maximum flips maxflips

and returns a model that satisfies the formula or failure. The algorithm begins 
by assigning truth values to

the atoms randomly, ie. generating a random model. Then it proceeds to flip the 
value of an atom from one

of the unsatisfied clauses until it is able to find a model that satisfies the 
formula or reaches the maximum

number of flips.

In order to select which atom from the currently selected clause to flip, it 
follows two strategies:

1. Either flip any atom randomly.

2. Or flip the atom that maximizes the number of satisfied clauses in the 
formula.

The choice to flip randomly is followed with probability p.

1.atomsClause :: Clause ! [Atom] This function must take a Clause and return 
the set of Atoms of

that Clause. Note that the set should not contain any duplicates.

2. atoms :: Formula![Atom] This function must take a Formula return the set of 
Atoms of a Formula.

Note that the set should not contain any duplicates.

3. isLiteral :: Literal ! Clause ! Bool This function returns True if the given 
Literal can be found

within the Clause.

4. flipSymbol :: Model ! Atom ! Model This function must take a Model and an 
Atom and flip the

truth value of the atom in the model.


Now I've done the first 3 I need some help with the last one, Here is the code:

module Algorithm where


import System.Random

import Data.Maybe

import Data.List


type Atom = String

type Literal = (Bool,Atom)

type Clause = [Literal]

type Formula = [Clause]

type Model = [(Atom, Bool)]

type Node = (Formula, ([Atom], Model))


atomsClause :: Clause - [Atom]

atomsClause = nub . map snd


atoms :: Formula - [Atom]

atoms =atomsClause . concat


isLiteral :: Literal - Clause - Bool

isLiteral (b,a) cs = or[x==b  y==a|(x,y)-cs]


flipSymbol :: Model - Atom - Model

flipSymbol = undefined
---the last one
Thank you.






  ___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] plugins and internal error: stg_ap_v_ret

2011-01-31 Thread Michael Snoyman
Hi all,

I'm trying to convert wai-handler-devel to use plugins instead of
hint, but cannot even get some basic usages to work properly. I've put
together a minimal example that loads a WAI application from a
separate file and runs it, but this immediately causes the program to
crash saying:

loader: internal error: stg_ap_v_ret
(GHC version 6.12.3 for i386_unknown_linux)
Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Is this an actual bug in GHC, or am I misusing the plugins package?

The two source files:

MyModule.hs
{-# LANGUAGE OverloadedStrings #-}
module MyModule where

import Network.Wai
import Data.ByteString.Lazy.Char8 ()

myapp _ = responseLBS status200 [(Content-Type, text/plain)] myapp

loader.hs
import System.Plugins.Make
import System.Plugins.Load
import Network.Wai.Handler.Warp (run)

main :: IO ()
main = do
MakeSuccess _ obj - makeAll MyModule.hs []
LoadSuccess _ app - load_ obj [] myapp
run 3000 app

Thanks,
Michael

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell WalkSat algorithm implementation

2011-01-31 Thread Mihai Maruseac
On Mon, Jan 31, 2011 at 9:11 PM, Manolache Andrei-Ionut 
andressocrate...@yahoo.com wrote:

 I need some help if possible with the following problem.The WalkSat
 algorithm takes a formula, a probability 0 = p = 1, and a boundary of
 maximum flips maxflips
 and returns a model that satisfies the formula or failure. The algorithm
 begins by assigning truth values to
 the atoms randomly, ie. generating a random model. Then it proceeds to flip
 the value of an atom from one
 of the unsatisfied clauses until it is able to find a model that satisfies
 the formula or reaches the maximum
 number of flips.
 In order to select which atom from the currently selected clause to flip,
 it follows two strategies:
 1. Either flip any atom randomly.
 2. Or flip the atom that maximizes the number of satisfied clauses in the
 formula.
 The choice to flip randomly is followed with probability p.
 1.atomsClause :: Clause ! [Atom] This function must take a Clause and
 return the set of Atoms of
 that Clause. Note that the set should not contain any duplicates.
 2. atoms :: Formula![Atom] This function must take a Formula return the set
 of Atoms of a Formula.
 Note that the set should not contain any duplicates.
 3. isLiteral :: Literal ! Clause ! Bool This function returns True if the
 given Literal can be found
 within the Clause.
 4. flipSymbol :: Model ! Atom ! Model This function must take a Model and
 an Atom and flip the
 truth value of the atom in the model.

 Now I've done the first 3 I need some help with the last one, Here is the
 code:
 module Algorithm where

 import System.Random
 import Data.Maybe
 import Data.List

 type Atom = String
 type Literal = (Bool,Atom)
 type Clause = [Literal]
 type Formula = [Clause]
 type Model = [(Atom, Bool)]
 type Node = (Formula, ([Atom], Model))

 atomsClause :: Clause - [Atom]
 atomsClause = nub . map snd

 atoms :: Formula - [Atom]
 atoms =atomsClause . concat

 isLiteral :: Literal - Clause - Bool
 isLiteral (b,a) cs = or[x==b  y==a|(x,y)-cs]

 flipSymbol :: Model - Atom - Model
 flipSymbol = undefined ---the last one
 Thank you.


Hi,

I guess that

flipSymbol m a = map f m
  where
f (atom, value) = if a == atom then (atom, not value) else (atom, value)

should do the trick.

-- 
Mihai
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Typing problem

2011-01-31 Thread michael rice
I hadn't considered the types of the functions I call in the function I'm 
trying to write, something not usually needed in loosely typed languages with 
coercion, but something I'm going to have to make a habit of doing. One more 
thing to add to the check list.

Also, I had considered the numbers in the list to be integral if they didn't 
have decimal points, which inferred, for me, that polymorphic type a needed to 
be of a class that would accept either Integral or Floating values, i.e., Num.  
False reasoning.

Thanks, all.

Michael

--- On Mon, 1/31/11, Daniel Fischer daniel.is.fisc...@googlemail.com wrote:

From: Daniel Fischer daniel.is.fisc...@googlemail.com
Subject: Re: [Haskell-cafe] Typing problem
To: haskell-cafe@haskell.org
Cc: michael rice nowg...@yahoo.com
Date: Monday, January 31, 2011, 1:38 PM

On Monday 31 January 2011 18:29:59, michael rice wrote:
 I'm mapping a function over a list of data, where the mapping function
 is determined from the data.

 g f l = map (g l) l

g f l = map (f l) l

probably


 So

 g serialize prolog  -  [4,5,3,2,3,1]

 But I'm having typing problems trying to do a similar thing with a
 function that statistically normalizes data.

 See:
 http://people.revoledu.com/kardi/tutorial/Similarity/Normalization.html#
Statistic

 So

 g normalize [2,5,3,2]  - 
 [-0.7071067811865475,1.414213562373095,0.0,-0.7071067811865475]

 Is my typing for normalize too loose.

You can omit the type signatures and see what the compiler infers as the 
type. In this case, 


 normalize :: (Num a, Num b) = [a] - a - b
 normalize l = let (total,len) = sumlen l
                   avg = total/len
                   stdev = sqrt $ ((/) (len-1)) $ sum $ map ((** 2.0) .
 (subtract avg)) l in  ((/) stdev) . (subtract avg)

In the final result, I suppose it should be (/ stdev) and not ((/) stdev) 
[the latter is (stdev /), i.e. \x - stdev / x].

by sumlen's type, len has an Integral type. You want to use (/) to divide, 
which gives a Fractional constraint,

(/) :: Fractional a = a - a - a

Since it is not sensible for a type to be a member of both, the Fractional 
and Integral classes, you should convert len to the appropriate type with 
fromIntegral. For stdev, you call

sqrt :: Floating a = a - a
and
(**) :: Floating a = a - a

which means the list elements must have a type belonging to Floating
(you could replace the (** 2.0) with (^ 2), which would probably be better, 
but the Floating constraint remains due to the sqrt).
Finally, the resulting function is \x - (x - avg) / stdev, hence x must 
have the same type as abg and stdev, and the final result has the same 
type. Altogether,

normalize :: Floating a = [a] - a - a
normalize l =
  let (total, len0) = sumlen l
      len = fromIntegral len0
      avg = total/len
      stdev = sqrt $ sum [(x-avg)^2 | x - l] / (len-1)
  in (/ stdev) . subtract avg

but that gives nonsense if you pass a complex-valued list, so it might be 
better to restrict the type to

normalize :: RealFloat a = [a] - a - a

 Should I be using Floating rather than Num?

You have to, and one number type only (well, you could use two or three 
types if you compose with conversion functions, realToFrac for example).




  ___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell WalkSat algorithm implementation

2011-01-31 Thread Houdini

thank you
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/Haskell-WalkSat-algorithm-implementation-tp3365064p3365124.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Inheritance and Wrappers

2011-01-31 Thread MattMan

tldr: Can I make arbitrary instances of one class instantiate another without
using wrappers?

I'm new to Haskell, and am trying to implement some simple typeclasses for
doing algebra.  For example I have type class (simplified for the sake of
argument)

class AbGroup a where
add :: a - a - a

I would like any type instantiating Num to also be an abelian group:

instance (Num a) = AbGroup a where
 add i j = i+j,

but this doesn't compile because a is a variable, not a type constructor(or
something).  The problem is fixed, in a sense, If I introduce a wrapper
class

data Wrapper a = Wrap a
instance (Num a) = AbGroup (Wrapper a) where
 add (Wrap i) (Wrap j) = Wrap(i+j)

However, this is clumsy.  Is there something else I can do?  Thanks!

-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/Inheritance-and-Wrappers-tp3365126p3365126.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Inheritance and Wrappers

2011-01-31 Thread Steffen Schuldenzucker

On 01/31/2011 08:58 PM, MattMan wrote:

[...]

data Wrapper a = Wrap a
instance (Num a) =  AbGroup (Wrapper a) where
  add (Wrap i) (Wrap j) = Wrap(i+j)

However, this is clumsy.  Is there something else I can do?  Thanks
This is the normal approach. You can do funny things with the 
OverlappingInstances extension, but it is probably not what you want.


The problem is that the compiler only considers the heads of the 
instance declarations when determining which instance to use for a 
specific type. So an instance like this:


 instance (Num a) = AbGroup a where ...

means: Some type matching 'a' (that is, any type) is an instance of 
'AbGroup' if and only if it is an instance of 'Num'.


An additional instance like

 instance AbGroup SomeData where ...

would then conflict with the instance above: As 'SomeData' in particular 
matches the type 'a', the compiler does not know which one to choose. 
You could argue that the latter is more specific than the former, so 
the compiler should choose that one. This is exactly what 
OverlappingInstances does, but it can have more, unwanted effects.


You can make your wrapper code less clumsy by deriving some instances 
such as


 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
 data Wrapper a = Wrap a deriving (Eq, Ord, Read, Show, Num)

-- Steffen



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Inheritance and Wrappers

2011-01-31 Thread Daniel Fischer
On Monday 31 January 2011 20:58:02, MattMan wrote:
 tldr: Can I make arbitrary instances of one class instantiate another
 without using wrappers?

 I'm new to Haskell, and am trying to implement some simple typeclasses
 for doing algebra.  For example I have type class (simplified for the
 sake of argument)

 class AbGroup a where
 add :: a - a - a

 I would like any type instantiating Num to also be an abelian group:

 instance (Num a) = AbGroup a where
  add i j = i+j,

 but this doesn't compile because a is a variable, not a type
 constructor(or something).  The problem is fixed, in a sense, If I
 introduce a wrapper class

 data Wrapper a = Wrap a
 instance (Num a) = AbGroup (Wrapper a) where
  add (Wrap i) (Wrap j) = Wrap(i+j)

 However, this is clumsy.  Is there something else I can do?  Thanks!

Not really. You could enable the FexibleInstances extension, then your 
first instance would compile. But it would mean 'every type is an instance 
of AbGroup, and if you try to use it with something that isn't also a Num, 
it won't compile, also you can't have any other instances', not what you 
want. You could then also enable OverlappingInstances, which would allow 
you to write other instances, but that extension is widely regarded as 
dangerous (have to confess, I forgot what the dangers were, one was that 
instance selection doesn't always do what you want/expect).

Wrapper instances or specific instances are probably the best way (specific 
instances to be generated by a preprocessor or TH).

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Inheritance and Wrappers

2011-01-31 Thread Brandon S Allbery KF8NH
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 1/31/11 15:24 , Daniel Fischer wrote:
 want. You could then also enable OverlappingInstances, which would allow 
 you to write other instances, but that extension is widely regarded as 
 dangerous (have to confess, I forgot what the dangers were, one was that 
 instance selection doesn't always do what you want/expect).

Instance selection will still not look at the context, so multiple instances
would complain about needing IncoherentInstances, and if you add *that* then
it does something like taking the first matching instance it finds (again,
ignoring the context completely).

- -- 
brandon s. allbery [linux,solaris,freebsd,perl]  allb...@kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon university  KF8NH
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1HHNMACgkQIn7hlCsL25XFYgCgqLWUoZzYrZO54ydDY9kTa9RT
3VAAn0WgJzeWO5vvO4QP1pkEYL5tzxYB
=+6Pz
-END PGP SIGNATURE-

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Inheritance and Wrappers

2011-01-31 Thread Henning Thielemann


On Mon, 31 Jan 2011, MattMan wrote:


I'm new to Haskell, and am trying to implement some simple typeclasses for
doing algebra.  For example I have type class (simplified for the sake of
argument)

class AbGroup a where
   add :: a - a - a

I would like any type instantiating Num to also be an abelian group:

instance (Num a) = AbGroup a where
add i j = i+j,


If all methods of AbGroup can be defined for all Num types - why do you 
want an AbGroup at all? You could simply write functions with Num 
constraint.


You may be also interested in existing approaches to algebra in Haskell:
  http://www.haskell.org/haskellwiki/Mathematical_prelude_discussion


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Inheritance and Wrappers

2011-01-31 Thread Henning Thielemann


On Mon, 31 Jan 2011, Brandon S Allbery KF8NH wrote:


On 1/31/11 15:24 , Daniel Fischer wrote:

want. You could then also enable OverlappingInstances, which would allow
you to write other instances, but that extension is widely regarded as
dangerous (have to confess, I forgot what the dangers were, one was that
instance selection doesn't always do what you want/expect).


Instance selection will still not look at the context, so multiple instances
would complain about needing IncoherentInstances, and if you add *that* then
it does something like taking the first matching instance it finds (again,
ignoring the context completely).


Since the original poster classified himself as new to Haskell, I'm afraid 
that advanced and dangerous extensions are not the appropriate answer.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] companies using Haskell or other FP languages near Rochester?

2011-01-31 Thread Edward Amsden
I'm an undergraduate CS student (4th year status) looking for an co-op
or internship in the Rochester area. I'd really like to do something
with functional programming or Haskell specifically, but I'm not sure
if anyone in this area does that. Staying near Rochester is important
because I'd also like to take one or two classes at my school
(Rochester Institute of Technology) over the summer.

Any ideas?

-- 
Edward Amsden
Undergraduate
Computer Science
Rochester Institute of Technology
www.edwardamsden.com

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Packages all screwed up

2011-01-31 Thread Arnaud Bailly
Hello,
I recently tried to upgrade some package (eg. yesod) and it seems
that, in the process, I screwed up my Haskell packages setup.
When I am trying to do a simple:
 ghc --make Crete1941

It fails with message:

Loader\Communication.hs:14:7:
Could not find module `System.Process':
  Use -v to see a list of the files searched for.

which is quite annoying !

Is there a way to reconstruct a sane baseline ?

Thanks in advance
Arnaud

PS: In case it might be helpful, here is the output of ghc-pkg check -v

There are problems in package pandoc-1.6:
  dependency utf8-string-0.3.6-02c7018b15768d3d72b99557d0f847ff doesn't exist
There are problems in package zip-archive-0.1.1.6:
  dependency binary-0.5.0.2-0da250ded3b79a6e76d15de8e7ffc885 doesn't exist
  dependency utf8-string-0.3.6-02c7018b15768d3d72b99557d0f847ff doesn't exist
There are problems in package url-2.1.2:
  dependency utf8-string-0.3.6-02c7018b15768d3d72b99557d0f847ff doesn't exist
There are problems in package filestore-0.3.4.3:
  dependency utf8-string-0.3.6-02c7018b15768d3d72b99557d0f847ff doesn't exist
There are problems in package happstack-server-0.5.0.2:
  dependency utf8-string-0.3.6-02c7018b15768d3d72b99557d0f847ff doesn't exist
There are problems in package happstack-data-0.5.0.2:
  dependency binary-0.5.0.2-0da250ded3b79a6e76d15de8e7ffc885 doesn't exist
There are problems in package feed-0.3.7:
  dependency utf8-string-0.3.6-02c7018b15768d3d72b99557d0f847ff doesn't exist
There are problems in package SHA-1.4.1.3:
  dependency binary-0.5.0.2-0da250ded3b79a6e76d15de8e7ffc885 doesn't exist
There are problems in package hashed-storage-0.5.3:
  dependency binary-0.5.0.2-0da250ded3b79a6e76d15de8e7ffc885 doesn't exist
There are problems in package yesod-0.6.0.2:
  dependency cereal-0.3.0.0-835aef1b61feb29c879c2cdae5c16608 doesn't exist
  dependency clientsession-0.4.0.3-83420d6960f048ed87e049bcfa4d3d35
doesn't exist
  dependency neither-0.1.0-50e3e802c117062181b91d4cbd45270b doesn't exist
  dependency wai-0.2.2-11adeb24d79e447264a1c6aa73a257e8 doesn't exist
There are problems in package xss-sanitize-0.2.2:
  dependency utf8-string-0.3.6-02c7018b15768d3d72b99557d0f847ff doesn't exist
There are problems in package web-routes-0.23.0:
  dependency utf8-string-0.3.6-02c7018b15768d3d72b99557d0f847ff doesn't exist
There are problems in package wai-extra-0.2.4:
  dependency utf8-string-0.3.6-02c7018b15768d3d72b99557d0f847ff doesn't exist
  dependency wai-0.2.2-11adeb24d79e447264a1c6aa73a257e8 doesn't exist
  dependency zlib-bindings-0.0.0-c2a6f489bd57d072e884afc1d6466b99
doesn't exist
There are problems in package snap-server-0.2.11:
  dependency cereal-0.3.0.0-835aef1b61feb29c879c2cdae5c16608 doesn't exist
  dependency monads-fd-0.1.0.2-8e71857db7c17ae96ca5bff72f20d9fa doesn't exist
There are problems in package snap-core-0.2.11:
  dependency cereal-0.3.0.0-835aef1b61feb29c879c2cdae5c16608 doesn't exist
  dependency monads-fd-0.1.0.2-8e71857db7c17ae96ca5bff72f20d9fa doesn't exist
There are problems in package pureMD5-2.1.0.2:
  dependency binary-0.5.0.2-0da250ded3b79a6e76d15de8e7ffc885 doesn't exist
  dependency cereal-0.3.0.0-835aef1b61feb29c879c2cdae5c16608 doesn't exist
There are problems in package persistent-0.3.0.1:
  dependency neither-0.1.0-50e3e802c117062181b91d4cbd45270b doesn't exist
There are problems in package hsx-0.7.0:
  dependency utf8-string-0.3.6-02c7018b15768d3d72b99557d0f847ff doesn't exist
There are problems in package HStringTemplate-0.6.5:
  dependency utf8-string-0.3.6-02c7018b15768d3d72b99557d0f847ff doesn't exist
There are problems in package HSlim-0.1:
  dependency utf8-string-0.3.6-02c7018b15768d3d72b99557d0f847ff doesn't exist
There are problems in package hint-0.3.3.0:
  dependency utf8-string-0.3.6-02c7018b15768d3d72b99557d0f847ff doesn't exist
There are problems in package haskeline-0.6.3.1:
  dependency utf8-string-0.3.6-02c7018b15768d3d72b99557d0f847ff doesn't exist
There are problems in package happstack-state-0.5.0.2:
  dependency binary-0.5.0.2-0da250ded3b79a6e76d15de8e7ffc885 doesn't exist
  dependency happstack-data-0.5.0.2-80c87686add000961445ac7ad8f41385
doesn't exist
  dependency happstack-util-0.5.0.2-781b128492ee5ce69eb3c01f6e6a02bb
doesn't exist
There are problems in package happstack-ixset-0.5.0.2:
  dependency happstack-data-0.5.0.2-80c87686add000961445ac7ad8f41385
doesn't exist
  dependency happstack-util-0.5.0.2-781b128492ee5ce69eb3c01f6e6a02bb
doesn't exist
There are problems in package happstack-0.5.0.2:
  dependency happstack-data-0.5.0.2-80c87686add000961445ac7ad8f41385
doesn't exist
  dependency happstack-server-0.5.0.2-9d48ec4b8dd67d495020314c5d2b
doesn't exist
  dependency happstack-util-0.5.0.2-781b128492ee5ce69eb3c01f6e6a02bb
doesn't exist
  dependency utf8-string-0.3.6-02c7018b15768d3d72b99557d0f847ff doesn't exist
There are problems in package crypto-api-0.1.2.4:
  dependency cereal-0.3.0.0-835aef1b61feb29c879c2cdae5c16608 doesn't exist
There are problems in package 

Re: [Haskell-cafe] Packages all screwed up

2011-01-31 Thread Daniel Fischer
On Monday 31 January 2011 23:59:57, Arnaud Bailly wrote:
 Hello,
 I recently tried to upgrade some package (eg. yesod) and it seems
 that, in the process, I screwed up my Haskell packages setup.

Big time.


 When I am trying to do a simple:
  ghc --make Crete1941

 It fails with message:

 Loader\Communication.hs:14:7:
     Could not find module `System.Process':
       Use -v to see a list of the files searched for.

Scary. Does 'ghc-pkg list process' list
- no package process at all
- one package process in the global db
- more than one process (one in the global db)
- process in user db but not global ?

The first would mean your GHC is really borked and you'd need to reinstall.
The second and third would mean there's hope, four looks like a reinstall 
again.
Unfortunately, the error message lets me fear the first.


 which is quite annoying !

 Is there a way to reconstruct a sane baseline ?

1. Check whether ghc itself is affected, rename (or move, or delete if you 
think it's not worth saving) the directory your user db is in (ghc-pkg list 
process should tell you where if you don't know), so ghc doesn't see it. 
ghc-pkg check. If nothing is reported as broken, try compiling a programme 
or two using only the core libs, if it works, you probably don't need to 
reinstall ghc, if not, you have to start from zero.

2. If ghc itself is okay, you can decide whether you want to start fresh, 
then delete the old directory and cabal install what you need/want. If you 
think trying to rescue what you have and is not broken is worth the effort, 
ghc-pkg unregister the broken packages and cabal install them again.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Packages all screwed up

2011-01-31 Thread Antoine Latter
On Mon, Jan 31, 2011 at 4:59 PM, Arnaud Bailly arnaud.oq...@gmail.com wrote:
 Hello,
 I recently tried to upgrade some package (eg. yesod) and it seems
 that, in the process, I screwed up my Haskell packages setup.
 When I am trying to do a simple:
 ghc --make Crete1941

What command(s) did you issue to upgrade some packages?
Were you trying to do a user or global install?

When ghc loads packages, I've had cases where packages in the user db
would shadow packages in the global db, causing *other* packages in
the global db to report as broken.

Thanks,
Antoine

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Inheritance and Wrappers

2011-01-31 Thread MattMan

\quote
Henning Thielemann wrote:
 
 If all methods of AbGroup can be defined for all Num types - why do you 
 want an AbGroup at all? You could simply write functions with Num 
 constraint.
 
 

Well, I'd rather not have to implement (*), abs, etc on every abelian group.



You may be also interested in existing approaches to algebra in Haskell:
   http://www.haskell.org/haskellwiki/Mathematical_prelude_discussion



Yes, in fact I am!  Thanks for the suggestion; it seems numeric-prelude
does [most of] the things I want.  Thanks all.
-- 
View this message in context: 
http://haskell.1045720.n5.nabble.com/Inheritance-and-Wrappers-tp3365126p336.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] plugins and internal error: stg_ap_v_ret

2011-01-31 Thread Andy Stewart
Hi Michael,

plugins use it's own function instead GHC API, so it's easy to break
with new version GHC.

  -- Andy

Michael Snoyman mich...@snoyman.com
writes:

 Hi all,

 I'm trying to convert wai-handler-devel to use plugins instead of
 hint, but cannot even get some basic usages to work properly. I've put
 together a minimal example that loads a WAI application from a
 separate file and runs it, but this immediately causes the program to
 crash saying:

 loader: internal error: stg_ap_v_ret
 (GHC version 6.12.3 for i386_unknown_linux)
 Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

 Is this an actual bug in GHC, or am I misusing the plugins package?

 The two source files:

 MyModule.hs
 {-# LANGUAGE OverloadedStrings #-}
 module MyModule where

 import Network.Wai
 import Data.ByteString.Lazy.Char8 ()

 myapp _ = responseLBS status200 [(Content-Type, text/plain)] myapp

 loader.hs
 import System.Plugins.Make
 import System.Plugins.Load
 import Network.Wai.Handler.Warp (run)

 main :: IO ()
 main = do
 MakeSuccess _ obj - makeAll MyModule.hs []
 LoadSuccess _ app - load_ obj [] myapp
 run 3000 app

 Thanks,
 Michael


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Loading bitmap with xlib

2011-01-31 Thread Conrad Parker
On 31 January 2011 21:40, Francesco Mazzoli f...@mazzo.li wrote:
 Francesco Mazzoli f at mazzo.li writes:

 At the end I gave up and I wrote the function myself:

 http://hpaste.org/43464/readbitmapfile


cool ... the listed maintainer for the Xlib bindings is
librar...@haskell.org. Perhaps you could prepare a patch and send it
there? (does anyone know if there is an actual maintainer?)

Conrad.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Automatically move cursor focus in split window in haskell-mode in emacs on load (C-c C-l) command?

2011-01-31 Thread Steven Collins
I'm using haskell-mode-2.8.0 and emacs 22.2.1 on Ubuntu 9.10

The following elisp code works for me to change the focus to the GHCi buffer
(window) after the C-c C-l command in Haskell Mode.  Try this in your .emacs
file.


(defadvice inferior-haskell-load-file (after change-focus-after-load)
  Change focus to GHCi window after C-c C-l command
  (other-window 1))

(ad-activate 'inferior-haskell-load-file)

I have this after the haskell mode configuration section of my .emacs file.

Remeber to go to the Emacs-lisp menu and 'Byte-compile and Load' after
adding the above code to your .emacs file.

  To understand what the elisp code is doing you can go to the help menu in
emacs, then drill down via 'Search Documentation ' , then 'Find any object
by name'.  Which will put you in the mini-buffer.  Type in either defadvice
or ad-activate to see the documentation for these functions. If you are a
little rusty on elisp this documentation may be a little hard to understand.

  Basically this is what's happening.  The function that is bound to the C-c
C-l command is inferior-haskell-load-file.  Which is an elisp function name
and part of the elisp haskell mode code.  The defadvice is kind of
overloading this function.   We are telling emacs that 'after' executing the
'inferior-haskell-load-file' function,  execute our new function who's name
is 'change-focus-after-load'.  The body of our function is just one
expression (other-window 1).
  This is the kind of stuff that makes it easy to modify (hack)
the functionality of emacs to do what you want.

I hope this helps and enjoy hacking in Haskell
Steven
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Cabal ignores ld-options? - 2011 remix

2011-01-31 Thread Ryan Newton
Oops, I guess I misinterpreted package description.  It did sound a little
dangerous ;-).

What you suggested also worked.  I'm in good shape now.

Thanks again,
   -Ryan

On Mon, Jan 31, 2011 at 11:24 AM, Duncan Coutts 
duncan.cou...@googlemail.com wrote:

 On Mon, 2011-01-31 at 09:52 -0500, Ryan Newton wrote:
  Victory!  Thanks!
 
  Well.. mostly victory ;-).  I've got it in a state where the .cabal
  file rewriting works if cabal configure is called separately from
  cabal build/install so that the latter reads the modified
  configuration file.

 Yikes! Don't actually modify the .cabal file on disk. I meant just
 modify the data structure that gets passed around.

  As for portability...  I'm afraid I don't personally do any
  development on Windows.  Presumably the goal is for hackage packages
  to work without requiring Cygwin/make/etc?

 Right.

 Duncan


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Splittable random numbers

2011-01-31 Thread Ryan Newton
Small update:

I got the first results from the hardware accelerated version on a 3.33 ghz
westmere machine.  Right now it does twice as well as the Gladman software
version, which is also twice as well as the System.Random stdgen, and 1000
times faster than a the Haskell implementation of AES that I got from the
Crypto package:

 How many random numbers can we generate in a second on one thread?
  Cost of rdtsc (ffi call):84
  Approx getCPUTime calls per second: 209,798
  Approx clock frequency:  3,331,093,772
  First, timing with System.Random interface:
 76,811,104 random ints generated [constant zero gen]
 14,482,725 random ints generated [System.Random stdGen]
 16,061 random ints generated [PureHaskell/reference]
 32,309 random ints generated [PureHaskell]
  2,401,893 random ints generated [Gladman inefficient]
 15,980,625 random ints generated [Gladman]
  2,329,500 random ints generated [IntelAES inefficient]
 32,383,799 random ints generated [IntelAES]
  Comparison to C's rand():
 71,392,408 random ints generated [rand/store in C loop]
 71,347,778 random ints generated [rand in Haskell loop]
 71,324,158 random ints generated [rand/store in Haskell loop]

This is what Burton Smith originally thought, that AES based RNG would be
pretty fast and even faster with hardware acceleration.

-Ryan



On Mon, Jan 31, 2011 at 1:25 AM, Ryan Newton new...@mit.edu wrote:

 Hi Cafe,

 I've included Gladman's efficient, portable C implementation of AES
 generating random numbers now, and the hardware-accelerated version is
 working too.  I'm currently seeing higher throughput for even the software
 based version than the builtin stdGen:


   First, timing with System.Random interface:
  13,051,964 random ints generated [System.Random stdGen]  ~ 252
 cycles/int
  15,635 random ints generated [PureHaskell/reference] ~ 210,763
 cycles/int
  31,159 random ints generated [PureHaskell]   ~ 105,757
 cycles/int
   2,180,488 random ints generated [Gladman inefficient]   ~ 1,511
 cycles/int
  15,015,095 random ints generated [Gladman]   ~ 219
 cycles/int

 That seems like a good argument for cryptographic RNGs to me!

 I'm having a lot of trouble getting cabal to build/install it
 successfully.  You can see what I've got there now.  I'd be interested to
 know if anyone else can build it successfully.  It should work -- but only
 by building the assembly code into a .so and assuming the build directory is
 /opt/intel-aes ;-).

 I don't have real numbers for the hardware version yet because the Westmere
 machine I'm logged into is redhat 5.4 and is giving me GLIBC_2.7 not found
 errors.  You can run it for correctness purposes using an emulation tool
 called sde (software development 
 emulator)http://software.intel.com/en-us/articles/intel-software-development-emulator/that's
  based on dynamic binary translation.

 -Ryan

 P.S. Checkout command:
 git clone git://github.com/rrnewton/intel-aes.git





 On Sat, Jan 29, 2011 at 8:52 AM, Ryan Newton rrnew...@gmail.com wrote:

  perhaps performance? Is this approach less robust with a faster,
 non-cryptographic RNG?


 Yes, I don't understand that either.  Is there a reason that using a
 weaker PRNG in this case is WORSE than using it in the non-splitting case?
 Is that why there is more of an impetus to use the cryptographic approach in
 this case?

 Anyway, taking for granted that the Burton approach is a useful thing to
 have implemented, I started developing a package for this stuff -- AES based
 RNG including both a haskell implementation and wrapping an AESNI-based C
 one .  I haven't posted it to Hackage yet, but you can find the git
 repository here:

 https://github.com/rrnewton/intel-aes

 If you build with cabal and run the benchmark-intel-aes-rng executable, it
 will give you a breakdown like this:

 How many random numbers can we generate in a second on one thread?
   Cost of rdtsc (ffi call):83
   Approx getCPUTime calls per second: 205,640
   Approx clock frequency:  3,306,891,339
   First, timing with System.Random interface:
193,178,901 random ints generated [constant zero gen]
 14,530,358 random ints generated [System.Random stdGen]
 16,346 random ints generated [BurtonGenSlow/reference]
 32,965 random ints generated [BurtonGenSlow]
   Comparison to C's rand():
118,766,285 random ints generated [rand/store in C loop]
114,668,028 random ints generated [rand / Haskell loop]
114,675,116 random ints generated [rand/store Haskell]

 At the moment this is Haskell-only, I haven't included the wrapped Intel
 assembly code library yet.  As you can see, the pure-Haskell AES based RNG
 (BurtonGenSlow) is pretty slow.

 Would anyone else be interested in running those RNG testing tools
 (diehard, big crush) on this to make sure it is working correctly?

 Also I'd be happy if 

Re: [Haskell-cafe] Packages all screwed up

2011-01-31 Thread Arnaud Bailly
Hi,
Thanks for your answers.

I did

 cabal upgrade yesod

As for the user/global issue, I think I tried a user install, this is
default isn't it?

Looks like I will have to reinstall everything :-(

Arnaud

On Tue, Feb 1, 2011 at 1:34 AM, Antoine Latter aslat...@gmail.com wrote:
 On Mon, Jan 31, 2011 at 4:59 PM, Arnaud Bailly arnaud.oq...@gmail.com wrote:
 Hello,
 I recently tried to upgrade some package (eg. yesod) and it seems
 that, in the process, I screwed up my Haskell packages setup.
 When I am trying to do a simple:
 ghc --make Crete1941

 What command(s) did you issue to upgrade some packages?
 Were you trying to do a user or global install?

 When ghc loads packages, I've had cases where packages in the user db
 would shadow packages in the global db, causing *other* packages in
 the global db to report as broken.

 Thanks,
 Antoine


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe