Re: [Haskell-cafe] Re: Problems with Haskell Platform

2010-06-04 Thread Brandon S. Allbery KF8NH

On Jun 3, 2010, at 20:27 , Jens Petersen wrote:

I often find myself hitting Ctrl-C at cabal install HACKAGE to run
yum install ghc-DEPENDENCY-devel
and before returning to run cabal install again.

It would be nice to automate this in some way - cabal-install  
plugins, anyone??



Supposedly a future Cabal extension will be to, instead of installing,  
write out a package for a vendor packaging system (yum, apt, yast,  
what have you).  Consider contributing to that effort.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Efficient string construction

2010-06-04 Thread Ketil Malde
Daniel Fischer daniel.is.fisc...@web.de writes:

 So why is there a UTF8 implementation for bytestrings? Does that not
 duplicate what Text is trying to do? If so, why the duplication?

 I think Data.ByteString.UTF8 predates Data.Text.

One difference is that Data.Text uses UTF-16 internally, not UTF-8.

 When is each library more appropriate?

Much data is overwhelmingly ASCII, but with an option for non-ASCII in
comments, labels, or similar.  E.g., for biological sequence data, files
can be large (the human genome is about 3GB) and non-ascii characters
can only occur in sequence headers which constitute a miniscule fraction
of the total data.  So I use ByteString for this.

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ICFP Programming Contest

2010-06-04 Thread Wouter Swierstra
This year's ICFP Programming Contest will begin on June 18th (12:00
Noon GMT) and will run till June 21st (12:00 Noon GMT). As in the
previous editions, this is your chance to show that your favorite
programming language is better than all others! The problem statement
and further information will become available at:

http://icfpcontest.org/2010/

Feel free to contact ifcpcont at imn dot htwk-leipzig dot de for
further questions. Good luck!

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


Re: [Haskell-cafe] Re: Problems with Haskell Platform

2010-06-04 Thread Don Stewart
allbery:
 On Jun 3, 2010, at 20:27 , Jens Petersen wrote:
 I often find myself hitting Ctrl-C at cabal install HACKAGE to run
 yum install ghc-DEPENDENCY-devel
 and before returning to run cabal install again.

 It would be nice to automate this in some way - cabal-install plugins, 
 anyone??


 Supposedly a future Cabal extension will be to, instead of installing,  
 write out a package for a vendor packaging system (yum, apt, yast, what 
 have you).  Consider contributing to that effort.


However, we have tools for some distros that do this, and some distro
tools support it directly (e.g. bauerbill --hackage on Arch Linux
knows how to ask cabal2arch to translate the .cabal file).

Contribut to yum to allow pulling from hackage, by calling cabal2yum?

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


[Haskell-cafe] Haskell opportunity at investment bank

2010-06-04 Thread Pearse, Chris
Hello,

I'm looking for a developer with expertise in Haskell for an investment
bank in London. The role will involve working on a multi-asset,
multi-region, pricing, risk and trade lifecycle solution for the
wholesale banking division. Solutions are developed using Java, C#/WPF,
C++ and make heavy use of Haskell.

The requirement is for an experienced developer with in-depth knowledge
of functional programming in Haskell - ideally in a commercial
environment.

If interested, please feel free to send your CV through or call me to
discuss.

Thanks,

Chris Pearse
0207 469 5050
http://www.linkedin.com/pub/3/9a1/142 


---

Huxley Associates - Professional Recruitment Solutions



Established in 1995, Huxley Associates is an international recruitment 
consultancy. We provide bespoke recruitment services to the Accountancy  
Finance, Banking Technology, Energy, Engineering, Global Markets, Human 
Resources, IT, Oil  Gas, Sales  Marketing, and Supply Chain sectors. With 
over 400 specialist recruitment professionals, we are consistently able to meet 
the high recruitment needs of a diverse range of companies across the UK, 
Europe, Asia and the United States.



This email message may contain confidential and/or privileged information, and 
is intended solely for the addressee(s).

If you have received this email in error, please notify Huxley Associates 
immediately. Unauthorised copying, disclosure

or distribution of the material in this email is forbidden. If you do not want 
to receive emails from us about our services in

future, or if you want to query or qualify how your personal data is held by us 
(for details on this see our privacy statement

http://www.huxley.co.uk/privacy_policy.html ) please e-mail 
audit.d...@huxley.com.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Efficient string construction

2010-06-04 Thread Daniel Fischer
On Friday 04 June 2010 00:41:58, Bryan O'Sullivan wrote:
 On Thu, Jun 3, 2010 at 9:16 AM, Daniel Fischer 
daniel.is.fisc...@web.dewrote:
  String can be quite memory efficient. As a stupid example,
 
  length (replicate 1000 'a')
 
  will need less memory than the equivalents using ByteString or Text.

 Actually, this will be fused with Data.Text, and should execute more
 quickly and in less space than String.

Right, forgot about fusion. However, that requires the code to be compiled 
with optimisations, I think (well, one should never compile ByteString or 
Text code without).

In which case

{-# RULES
length/replicate forall n x. length (replicate n x) = max 0 n
   #-}

would be at least as good as the Data.Text thing ;)

Or, to be more fair, if you use Data.List.Stream, it should be fused too 
and be equally efficient as Data.Text.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Fwd: [Haskell-cafe] Weird socket problem on Mac OS X

2010-06-04 Thread Arnaud Bailly
-- Forwarded message --
From: Arnaud Bailly arnaud.oq...@gmail.com
Date: Fri, Jun 4, 2010 at 11:59 AM
Subject: Re: [Haskell-cafe] Weird socket problem on Mac OS X
To: Antoine Latter aslat...@gmail.com


Hello,
I managed to solve the problem using Network.Socket instead of
Network. Is this a bug or a feature ?

Arnaud

On Fri, Jun 4, 2010 at 7:11 AM, Arnaud Bailly arnaud.oq...@gmail.com wrote:
 Yes, I have also seen the other post on the same topic, but it seemed
 to refer to the PortNumber in Network.Socket with a PortNum
 constructor I think, not the one in Network (but I am probably
 misleading myself as one is a reexportation of the other...).
 But then I got.

 Slim\SlimClientIO.hs:26:51:
    No instance for (Num PortID)
      arising from a use of `fromInteger'
                   at Slim\SlimClientIO.hs:26:51-61
    Possible fix: add an instance declaration for (Num PortID)
    In the first argument of `($)', namely `fromInteger'
    In the expression: fromInteger $ slimport $ slimConfig st
    In the definition of `port':
        port = fromInteger $ slimport $ slimConfig st

 :-(
 Thanks

 Arnaud

 On Fri, Jun 4, 2010 at 1:46 AM, Antoine Latter aslat...@gmail.com wrote:
 Hi Arnaud,

 One thing you might want to try is to stop using the PortNumber data
 constructor, and instead rely on 'fromInteger' to do the right thing.

 The data constructor assumes that it's argument is in network byte order,
 which won't always be the case.

 It's not obvious that the constructor should be avoided - this is the second
 time today I've seen this!

 Take care,
 Antoine

 On Jun 3, 2010 5:13 PM, Arnaud Bailly arnaud.oq...@gmail.com wrote:

 Hello,
 I have the following code which works ok on Linux and Windows XP, but
 fails on Mac OS X with error message:

 Connect: does not exist (connection refused)

 The server:

    doStartstate = do pr - liftIO $ runProcess  ...
                                    liftIO $ threadDelay 50
                                   st - get
                                   put st { slimHandle = Just pr }


 The client:

    fetchAnswers st msgs = liftIO $! do let port = PortNumber $
 fromInteger $ port $ config st
                                        cnx - connectTo localhost port

 Help most welcome, thanks

 Arnaud
 ___
 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] Re: Problems with Haskell Platform

2010-06-04 Thread Ivan Lazar Miljenovic
Don Stewart d...@galois.com writes:

 allbery:
 Supposedly a future Cabal extension will be to, instead of installing,  
 write out a package for a vendor packaging system (yum, apt, yast, what 
 have you).  Consider contributing to that effort.


 However, we have tools for some distros that do this, and some distro
 tools support it directly (e.g. bauerbill --hackage on Arch Linux
 knows how to ask cabal2arch to translate the .cabal file).

 Contribut to yum to allow pulling from hackage, by calling cabal2yum?

In general, I think this is a bad idea.

I don't know how it is in Arch, but for Gentoo we need to do a lot of
QA'ing to make sure our ebuilds generated with hackport work properly
(which is one reason why we don't churn ebuilds out as fast as you
generate PKBUILDs).  Part of the problem is probably that hackport isn't
as polished as cabal2arch, but a few other concerns we need to take care
of are:

1) Gentoo has categories for packages; whilst for Haskell stuff we can
   usually correctly guess dev-haskell/ as the category, there are a few
   exceptions (e.g. pandoc is in app-text/).  This is an even bigger
   problem when dealing with C deps, etc.

2) Dealing with flags: in most cases, we expose the Cabal flags as USE
   flags, so we need to take care of getting all those dependencies
   right.

3) Multiple versions: we have to take care of supporting multiple
   versions of GHC, as well as different versions of QuickCheck, etc.
   It doesn't help that due to the limitations of portage, Gentoo
   ebuilds do not support proper ranged dependencies.  However, this is
   most probably not an issue for most distributions where users get
   given one version of a specific package and they'll shut up and
   accept it.

4) It has to build always: related to the above, because we don't
   provide binaries, we have to ensure that packages are built reliably
   in a multitude of situations.  We recently had the situation where
   for some reason GHC 6.12.2 would build for someone but then wouldn't
   actually run; we eventually tracked down the problem to his usage of
   ccache: as of 6.12.2, the GHC wrapper script hardcodes which C
   compiler it was built with, and as ccache was only used when building
   packages the path to the C compiler in the GHC wrapper script was
   incorrect (so all our hacks to get this new feature of GHC working
   properly when users bootstrap had to be scrapped as they made the
   situation even worse in this case).

Again, these situations are mainly Gentoo-specific due to the unique
nature of the distribution (though distributions without categories
still have to ensure the Cabal-package-name-to-distribution-package-name
mapping is consistent and correct).  I would, however, imagine that in
general having end users use their package manager attempt to
automagically integrate Hackage packages into system packages would be
fraught with peril.

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANN: random-fu 0.1.0.0

2010-06-04 Thread James Andrew Cook
On Jun 3, 2010, at 10:03 PM, wren ng thornton wrote:

 Though, since RVar is a synonym for RVarT, I can't imagine why rvar is a 
 method instead of a shorthand defined outside of the class. (If RVar were 
 primitive then I could imagine performance reasons, but since it isn't...)

The reason for this is purely a matter of convenience combined with a bit of 
historical accident and/or laziness.  The RVar type predates the RVarT type, 
and thus rvar predates rvarT as well.  My personal idioms for defining 
distributions were invented before RVarT and have been slow to change.  These 
idioms involve defining the 'rvar' implementations in terms of the public 
interface of simpler distributions, which are mostly exporting plain 'RVar's in 
order to reduce the need for type annotations fixing 'n' elsewhere.

In particular, functions such as 'uniform' and 'normal' which directly 
construct RVars are very useful in defining the rvar implementation of other 
types.  I have been reluctant to drop the rvar function from the Distribution 
class because it is very useful to be able to define other Distribution 
instances in terms of these functions instead of the uglier explicit use of 
rvarT - e.g. rvarT StdUniform in place of just 'stdUniform'. Eventually I'll 
probably give up this particular objection – probably sooner rather than later 
now that you've made me think about it – but I'm presently in the state where I 
know it isn't right to have both (for some value of right)  but I don't 
know yet what a better solution is, given my conflicting objectives (one of 
which is to refrain from changing everything at once, so users have a chance to 
keep up with the library's evolution).

Making the convenience functions mentioned above return RVarT seems natural, 
but when I tried it I found it made their usage require type annotations in 
many other places to fix the type of the underlying monad, and I have not yet 
decided whether it is worth all that.  I may yet introduce separate RVarT-typed 
convenience functions as well, but I'm not sure I want to do that either.

Suggestions are welcome :)

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


[Haskell-cafe] alphanum in infix constructors (and possibly functions as well) - why not?

2010-06-04 Thread Ozgur Akgun
Hi all,

The constructor names in Haskell need to obey one of the two following
rules:
 - either starts with a capital letter and contains alphanumeric characters
afterwards, (including _ I guess)
 - or starts with a colon (:) and only contains symbols afterwards

The first one is used Prefix by default, and the second ose is used infix by
default.

What stops us from allowing alphanum characters appear in the Infix version
(after the colon)? Can't it be relaxed to only start woth a colon?

So I want to be able to say something like:

data Expr = Expr :   Expr  -- checks for LT betwen two Expr's
  | Expr :2  Expr  -- a different implementation of the
same thing maybe
  | Expr :veryfast Expr-- and the veryfast implementation of it

(just a silly example I could think of now.)


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


Re: [Haskell-cafe] ANN: random-fu 0.1.0.0

2010-06-04 Thread James Andrew Cook
On Jun 4, 2010, at 1:19 AM, Alexander Solla wrote:

 We don't necessarily have to compute the inverse of the distribution via 
 sampling to do it.  It can be done algebraically, in terms of the convolution 
 operator.  Since the types are enumerated, wouldn't something like... work?
 
 -- A set and binary operation.  We have an algebra.  I like the J for 'join'.
 -- With this algebra, we can use the real-complex analytical methods to
 -- interpret the terms later, if we want to actually reify a Distribution
 -- instance as a Real (Float, Double) function.
 
  data DistributionJ a = UniformDistribution Uniform a
 | ...
 | ExponentialDistribution Exponential a
 | DistributionJ a `Convolve` (DistributionJ a)
 
 
 -- I hope I understand the semantics for the PromptT monad.
  newtype RVarT m a = RVarT { unRVarT :: PromptT (Prim, DistributionJ) m a }
 
 I guess threading fst and snd in all the low level computations is inelegant, 
 but it's a step closer.

An algebraic solution would work as long as the user only made use of a very 
small set of supported operations.  Unfortunately, even detecting whether they 
have done so in any implementation supporting Monad is not really feasible.  
The Functor/Applicative/Monad classes allow inclusion of arbitrary functions in 
the construction of an RVar, which is a very big part of the usefulness of the 
system.  Even in a simple no-op defininion such as fmap id x, fmap has no way 
of discovering whether the function is id, negate, primes !!, or worse, 
so the only way (I believe) to effectively propagate the algebraic part would 
be to drop the Functor, Applicative and Monad instances and work with RVars 
solely via some combinator library.  At that point, why not just work with the 
symbolic form directly and choose at the end whether to sample or compute a 
pdf?  You could make DistributionJ an instance of Distribution to make it 
sampleable, and do precisely that.  In fact, that would probably be a pretty 
nifty thing to do.

-- James

PS - the usage of DistributionJ in the prompt wouldn't quite work, because a 
DistributionJ a would just be a standin for a computation of type m a where 
m is the monad in which the variable is eventually sampled.  There is no way 
to rediscover the particular constructor that was used for the prompt, for 
approximately the same reasons as above.___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] alphanum in infix constructors (and possibly functions as well) - why not?

2010-06-04 Thread Ivan Lazar Miljenovic
Ozgur Akgun ozgurak...@gmail.com writes:

 Hi all,

 The constructor names in Haskell need to obey one of the two following
 rules:
  - either starts with a capital letter and contains alphanumeric characters
 afterwards, (including _ I guess)
  - or starts with a colon (:) and only contains symbols afterwards

 The first one is used Prefix by default, and the second ose is used infix by
 default.

 What stops us from allowing alphanum characters appear in the Infix version
 (after the colon)? Can't it be relaxed to only start woth a colon?

The definition.  I believe this is probably to make parsing of
foo:bar (using your example below) unambiguous, the same as how
symbolic operators can't contain alphanumeric characters, etc.


 So I want to be able to say something like:

 data Expr = Expr :   Expr  -- checks for LT betwen two Expr's
   | Expr :2  Expr  -- a different implementation of the
 same thing maybe
   | Expr :veryfast Expr-- and the veryfast implementation
 of it

How does a data structure have a faster implementation? _

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Weird socket problem on Mac OS X

2010-06-04 Thread Antoine Latter
On Fri, Jun 4, 2010 at 12:11 AM, Arnaud Bailly arnaud.oq...@gmail.com wrote:
 Yes, I have also seen the other post on the same topic, but it seemed
 to refer to the PortNumber in Network.Socket with a PortNum
 constructor I think, not the one in Network (but I am probably
 misleading myself as one is a reexportation of the other...).
 But then I got.

 Slim\SlimClientIO.hs:26:51:
    No instance for (Num PortID)
      arising from a use of `fromInteger'
                   at Slim\SlimClientIO.hs:26:51-61
    Possible fix: add an instance declaration for (Num PortID)
    In the first argument of `($)', namely `fromInteger'
    In the expression: fromInteger $ slimport $ slimConfig st
    In the definition of `port':
        port = fromInteger $ slimport $ slimConfig st


Oops! I didn't read carefully enough. That's what I get for trying to
program without haddocks or GHCi in front of me.

I am glad you have something that works.

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


[Haskell-cafe] Re: Proposal: Sum type branches as extended types (as Type!Constructor)

2010-06-04 Thread Gabriel Riba
Jason Dagit dagit at codersbase.com writes:

 
 How will this proposal scale with data types that have multiple 
  alternatives that make sense?  No natural examples come to mind 
  so how about a contrived example:
 
 data List2 a = Nil | Cons a (List2 a) | Cons2 a a (List2 a)
 
 Now I want to define hd for both Cons and Cons2, but not Nil.  
Do I use an either type like this?
 hd :: Either (List2!Cons a) (List2!Cons2 a) - a
 
 It seems like some other syntax would be desirable here, maybe:
 hd :: List2!{Cons, Cons2} a - a
 
 How should it work for functions where no type signature is supplied?  
   Shouldit infer the type we would now and only enable the 
  subset of constructors when the type is explicit as above?
 
 Jason

I agree with your syntax proposal.

hd :: List2!{Cons, Cons2} a - a

in functions where no type signature, type inference could work as usual. 
  After normal types passes typechecker with type inference, 
  then Constructor matching could be checked.

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


Re: [Haskell-cafe] alphanum in infix constructors (and possibly functions as well) - why not?

2010-06-04 Thread Ozgur Akgun
On 4 June 2010 12:33, Ivan Lazar Miljenovic ivan.miljeno...@gmail.comwrote:

 Ozgur Akgun ozgurak...@gmail.com writes:
 [...]
 
  What stops us from allowing alphanum characters appear in the Infix
 version
  (after the colon)? Can't it be relaxed to only start woth a colon?

 The definition.  I believe this is probably to make parsing of
 foo:bar (using your example below) unambiguous, the same as how
 symbolic operators can't contain alphanumeric characters, etc.


I see.
Then people would need to put spaces between those things, right?
What a horrible consequence!


 
  So I want to be able to say something like:
 
  data Expr = Expr :   Expr  -- checks for LT betwen two Expr's
| Expr :2  Expr  -- a different implementation of the
  same thing maybe
| Expr :veryfast Expr-- and the veryfast implementation
  of it

 How does a data structure have a faster implementation? _



Well it might indicate to use a different function while evaluating the
expression.
Still not a good example, I know.

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


[Haskell-cafe] Strange GHC messages?

2010-06-04 Thread Liam O'Connor
Hi all, I've got some strange GHC output that doesn't seem to be
affecting my program adversely but I thought I should post about it
cos it's disquieting


mkUsageInfo: internal name? r{tv aIR}
mkUsageInfo: internal name? s{tv aIS}


It seems to be complaining about this newtype declaration:


 newtype ThreadStateM r s v = ThreadState { unbox :: StateT s (ReaderT r IO) v 
 }
deriving (Monad, Functor, MonadIO, MonadState s, MonadReader r)

(uses newtype deriving)

I'm not sure what the problem here is?

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


Re: [Haskell-cafe] alphanum in infix constructors (and possibly functions as well) - why not?

2010-06-04 Thread Ketil Malde
Ozgur Akgun ozgurak...@gmail.com writes:

 Then people would need to put spaces between those things, right?
 What a horrible consequence!

I like to think that Haskell is a language where aesthetics matter.  So,
in my opinion this is indeed a horrible consequence.

I find mixing of symbols and letters in identfiers to be in itself
aesthetically inferior, and there's already more than enough
whitespace-dependent parsing warts in Haskell.

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] alphanum in infix constructors (and possibly functions as well) - why not?

2010-06-04 Thread Ozgur Akgun
OK I back up. I justed wanted it to happen for a moment :)

You're right, ambiguity in parsing and a lot of whitespace-dependency are
things to avoid.

Best,

On 4 June 2010 14:25, Ketil Malde ke...@malde.org wrote:

 Ozgur Akgun ozgurak...@gmail.com writes:

  Then people would need to put spaces between those things, right?
  What a horrible consequence!

 I like to think that Haskell is a language where aesthetics matter.  So,
 in my opinion this is indeed a horrible consequence.

 I find mixing of symbols and letters in identfiers to be in itself
 aesthetically inferior, and there's already more than enough
 whitespace-dependent parsing warts in Haskell.

 -k
 --
 If I haven't seen further, it is by standing in the footprints of giants
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe




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


[Haskell-cafe] How to Show an Operation?

2010-06-04 Thread Martin Drautzburg
Dear all,

If I have a problem where I have to select from a set of operations, how would 
I print the result?

Example: If I can chose from (x+y), (x*y), (x^2+y)...
and I feed them all into my problem solver
and it finds that (x*y) is right, how can I print that string?

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


Re: [Haskell-cafe] How to Show an Operation?

2010-06-04 Thread Ozgur Akgun
One way woul be to represent them usnig a data structure. If it's only
artihmetic operations, it should be pretty easy.

data Arith = Var String
   | Plus Artih Arith
   | Mult Arith Arith
   | Pow  Arith Arith

x + y would be Plus (Var x) (Var y), so on so forth..

You can even use infix constructors like :+:, :*:, :^:


On 4 June 2010 16:37, Martin Drautzburg martin.drautzb...@web.de wrote:

 Dear all,

 If I have a problem where I have to select from a set of operations, how
 would
 I print the result?

 Example: If I can chose from (x+y), (x*y), (x^2+y)...
 and I feed them all into my problem solver
 and it finds that (x*y) is right, how can I print that string?

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




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


Re: [Haskell-cafe] How to Show an Operation?

2010-06-04 Thread Daniel Fischer
On Friday 04 June 2010 17:37:16, Martin Drautzburg wrote:
 Dear all,

 If I have a problem where I have to select from a set of operations, how
 would I print the result?

 Example: If I can chose from (x+y), (x*y), (x^2+y)...
 and I feed them all into my problem solver
 and it finds that (x*y) is right, how can I print that string?

You'd have to pass the description string to the problem solver too.
If it was previously

solver :: Num a = Whatever - [a - a - a] - Result

it would become for example

solver :: Num a = Whatever - [(a - a - a, String)] - Result
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Reporting a problem with binary-0.5

2010-06-04 Thread Pete Chown
I've been trying to get in touch with the maintainers of the Binary 
package, to report an issue.  When I emailed the addresses given on 
Hackage, I got an automated response saying I had used an address that 
was no longer current.


I don't want to put pressure on anyone to fix my bug -- I didn't pay 
anything for Binary, so it wouldn't be fair for me to have that kind of 
expectation.  At the same time, I don't really want my bug report to go 
missing just because someone's email address has changed.  Does anyone 
know who I should be talking to?  Or is there a bug tracker for the 
Hackage packages somewhere?


I noticed this problem when I ran into some trouble with the network-dns 
package.  It would hang up as soon as I tried to send a query. 
Eventually I traced the problem to the binary module, and reduced it to 
this short test case:


module Main where

import qualified Data.Binary.Get as G
import qualified Data.ByteString.Lazy as B

main = do
  urandom - B.readFile /dev/urandom
  let urandomParser :: G.Get [Int]
  urandomParser = do
v - G.getWord32be
rest - urandomParser
return $ fromIntegral v : rest
  seeds = G.runGet urandomParser urandom

  print $ take 4 seeds

This code attempts to create an infinite list of random numbers -- a 
technique also used by network-dns.  It turns out that this code works 
with binary-0.4.4 but not with binary-0.5.0.2.  Both were built with 
ghc-6.12.1 on Ubuntu.  (I haven't tested with the intermediate versions 
of the binary module.)  It seems that with binary-0.5.0.2 there is some 
unwanted strictness; something is evaluated for the whole list, even 
though it is only the first few elements that are required.


Incidentally, if the test case is changed like this:

--- get_monad.hs2010-05-28 11:31:02.399202535 +0100
+++ get_monad2.hs   2010-05-28 13:44:25.515486013 +0100
@@ -1,10 +1,12 @@
 module Main where

+import Control.Monad
+
 import qualified Data.Binary.Get as G
 import qualified Data.ByteString.Lazy as B

 main = do
-  urandom - B.readFile /dev/urandom
+  urandom - liftM (B.take 64) $ B.readFile /dev/urandom
   let urandomParser :: G.Get [Int]
   urandomParser = do
 v - G.getWord32be

the program exits with an error:

get_monad2.hs: too few bytes. Failed reading at byte position 68

This seems to demonstrate that the program is reading more data than it 
needs to.


Thanks,
Pete

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


[Haskell-cafe] Re: Proposal: Sum type branches as extended types (as Type!Constructor)

2010-06-04 Thread Gabriel Riba
Edward Kmett suggests the use of @ instead of !

Edward Kmett wrote:

This is just a form of refinement type. Googling the term should turn up a
 couple dozen papers on the topic.

You can emulate them (and more) with phantom types in the existing 
 type system, though admittedly the encoding is occasionally uncomfortable. 
  As a result there hasn't been much interest in them from on high.

And a minor technical issue with the use of ! there is that it would be 
  awkward from a grammar perspective because it would require that ! bind 
  more tightly than juxtaposition, but only when parsing a type. 
  Another syntactic operator like @ that already binds very tightly 
  might be more appropriate.

-Edward Kmett

New proposal draft:

Proposal: Type supplement for constructor specific uses of sum types

Purpose: Avoid error clauses (runtime errors), exception control or Maybe
 types in partially defined (constructor specific) functions on sum types.

As an example, with

   data List a = Nil | Cons a (List a)  

* Actual system, with runtime errors (as in GHC Data.List head) or 
exception throwing or optional Maybe results.

   hd :: List a - a
   hd (Cons x _) - x
   hd Nil - error error: hd: empty list -- error or exception throwing

* Proposed system extending types with a suffix @ Constructor or @
{Constructor1, Constructor2, ..}

   hd :: List @ Cons a - a
   hd (Cons x _) = x

The caller must do pattern matching before applying the constructor-specific
function.

In ''var @ (Constructor {})'' the compiler should set a type supplement
property for ''var'' to the specified pattern constructor and check 
the supplement when used in a constructor specific parameter position.


using it:

   accumHead :: (a-b) - a - List a - b

   accumHead f accum list = case list of

li @ Cons {} - f accum $ hd li  -- typeSupplementOf li == 'Cons'
  -- should pass typechecker at ''hd'' for 
List!Cons

li @ Nil  - f accum $ hd li -- compiler error !! 
-- typeSupplementOf li == 'Nil' ; no match

_ - f accum $ hd list   -- compiler error !! 
   -- typeSupplementOf list == Nothing ; no match

_ - accum   -- default closing pattern matching exhaustivity.

(from Jason Dagit contribution) For more than one constructor say 

  data List2 a = Nil | Cons a (List2 a) | Cons2 a a (List2 a)

hd :: List2 @ {Cons, Cons2} a - a



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


Re: [Haskell-cafe] Reporting a problem with binary-0.5

2010-06-04 Thread Ketil Malde
Pete Chown 1...@234.cx writes:

 This code attempts to create an infinite list of random numbers -- a
 technique also used by network-dns.  It turns out that this code works
 with binary-0.4.4 but not with binary-0.5.0.2.

There was a deliberate change in strictness in 0.5 making binary strict,
which apparently speeds up GHC.  I ran into the same problem, but have
no better workaround than to require binary  0.5 in my .cabal.

-k

(I made a note about this at 
http://blog.malde.org/index.php/2010/05/22/snagged/)
-- 
If I haven't seen further, it is by standing in the footprints of giants
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Reporting a problem with binary-0.5

2010-06-04 Thread Alexey Khudyakov
On Fri, Jun 4, 2010 at 8:02 PM, Pete Chown 1...@234.cx wrote:
 I've been trying to get in touch with the maintainers of the Binary package,
 to report an issue.  When I emailed the addresses given on Hackage, I got an
 automated response saying I had used an address that was no longer current.

 I don't want to put pressure on anyone to fix my bug -- I didn't pay
 anything for Binary, so it wouldn't be fair for me to have that kind of
 expectation.  At the same time, I don't really want my bug report to go
 missing just because someone's email address has changed.  Does anyone know
 who I should be talking to?  Or is there a bug tracker for the Hackage
 packages somewhere?

 I noticed this problem when I ran into some trouble with the network-dns
 package.  It would hang up as soon as I tried to send a query. Eventually I
 traced the problem to the binary module, and reduced it to this short test
 case:

 module Main where

 import qualified Data.Binary.Get as G
 import qualified Data.ByteString.Lazy as B

 main = do
  urandom - B.readFile /dev/urandom
  let urandomParser :: G.Get [Int]
      urandomParser = do
        v - G.getWord32be
        rest - urandomParser
        return $ fromIntegral v : rest
      seeds = G.runGet urandomParser urandom

  print $ take 4 seeds

This issue was discussed on the list before. Get monad definition
was changed in binary 0.5.0.2. It was made strict and evaluation
of result of runGet is forced. This increased performance but
broke programs which relies on lazyness to work.

Here is code I use to work around this issue:

 runGetStream :: Get a - ByteString - [a]
 runGetStream getter bs = unfoldr step bs
 where
   step bs = case runGetState getOne bs 0 of
   (Nothing, _,   _   ) - Nothing
   (Just x,  bs', off') - Just (x, bs')
   getOne = do empty - isEmpty
   if empty
 then return Nothing
 else Just $ getter
 ...
 seeds = runGetStream (fromInteger $ getWord64be) urandom
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Reporting a problem with binary-0.5

2010-06-04 Thread Alexey Khudyakov
On Fri, Jun 4, 2010 at 8:31 PM, Alexey Khudyakov
alexey.sklad...@gmail.com wrote:
 Here is code I use to work around this issue:

Forgot to mention. This code checks for end of input. Your data is
infinite so you simplify
definition if you like
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Tricks with GMap -- question about conflicts w/ indexed type families

2010-06-04 Thread Ryan Newton
GMaps -- families of map implementations indexed by the key type --
are an example on the wiki:

  http://www.haskell.org/haskellwiki/GHC/Type_families

I've been using something like this myself.  It sure would be nice to
have a fully developed version on Hackage, and I may try to submit
this myself if no one else has already done it.  But I'm running into
a problem in achieving a particular optimization that I want --
namely, small tuple keys packed into Ints.

For example, with a key type (Int16,Int16) it's possible to pack the
key into a plain Int and use Data.IntMap.

In fact, in the rough/partial implementation here
(http://people.csail.mit.edu/newton/gmap/GMap.hs) I have a class for
things that fit in a word:

class FitInWord v where
  toWord   :: v - Word
  fromWord :: Word - v

(Or fitInInt for that matter.)  Which includes things like small tuples:

instance FitInWord (Int16,Int16) where
  toWord (a,b) = shiftL (fromIntegral a) 16 + (fromIntegral b)
  fromWord n = (fromIntegral$ shiftR n 16,
fromIntegral$ n .. 0x)

(If you know a better idea than using templates/program generation to
generate every combination of small scalar tuples that fit in a
word let me know.)
What I would next *like* to do is something like the following:

import qualified Data.IntMap as DI
instance FitInWord t = GMapKey t where
 data GMap t v           = GMapInt (DI.IntMap v) deriving Show
 empty                   = GMapInt DI.empty
 lookup k    (GMapInt m) = DI.lookup (wordToInt$ toWord k) m
 insert k v  (GMapInt m) = GMapInt (DI.insert (wordToInt$ toWord k) v m)
 alter  fn k (GMapInt m) = GMapInt (DI.alter fn (wordToInt$ toWord k) m)
 toList      (GMapInt m) = map (\ (i,v) - (fromWord$ intToWord i, v)) $
   DI.toList m

The problem is that there's already a more general instance of GMapKey
that handles pairs by representing them as nested GMaps:

instance (GMapKey a, GMapKey b) = GMapKey (a, b) where
  data GMap (a, b) v= GMapPair (GMap a (GMap b v))
  

Ideally, I want both of these to coexist (and to prioritize the more
specific one).  With normal type classes, OverlappingInstances can
handle this, but with type families I get an error like the following:

   Conflicting family instance declarations:
  data instance GMap t v -- Defined at Intel/GMap.hs:108:7-10
  data instance GMap (a, b) v -- Defined at Intel/GMap.hs:225:7-10

Any fixes?

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


Re: [Haskell-cafe] Issue with connectTo function in network package

2010-06-04 Thread Roman Cheplyaka
* aditya siram aditya.si...@gmail.com [2010-06-03 22:30:33-0500]
 Hi all,
 I had an issue where using the connectTo [1] function would fail to
 connect to localhost if my wireless card was turned off. The moment
 I turned on my wireless connection it worked. But if I use connectTo
 with 127.0.0.1 [2] with my network off it works.
 
 I confirmed that localhost' resolves to 127.0.0.1 by pinging
 localhost from command line with the Internet off.
 
 Is this a bug in connectTo?
 
 -deech
 
 [1] connectTo localhost (PortNumber some_number)
 [2] connectTo 127.0.0.1 (PortNumber some_number)

How exactly did it fail? Did it throw an exception? If so, what was the
exception?

Which operating system did you observe that under?

If that was Linux, can you show the contents of the following files on
that system:

/etc/nsswitch.conf
/etc/hosts

-- 
Roman I. Cheplyaka :: http://ro-che.info/
Don't let school get in the way of your education. - Mark Twain
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe