Re: [Haskell-cafe] [Haskell] ANN: Cabal v1.18.0 released

2013-09-16 Thread Erik Hesselink
On Mon, Sep 16, 2013 at 10:16 AM, Henning Thielemann
lemm...@henning-thielemann.de wrote:

 On Wed, 4 Sep 2013, Johan Tibell wrote:

 * GHCi support. It's now much easier to use ghci when developing your
 packages, especially if those packages require preprocessors (e.g.
 hsc2hs).

 That's a great feature! How can I configure Cabal to start ghci with certain
 options? I like to enable more warnings. I could not find a documentation
 for the Cabal config file.

I assume a .ghci file, either in the project directory, or in your
home directory, still works. See also
http://www.haskell.org/ghc/docs/latest/html/users_guide/ghci-dot-files.html

Regards,

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


Re: [Haskell-cafe] Hoogle vs Hayoo

2013-08-23 Thread Erik Hesselink
On Thu, Aug 22, 2013 at 9:23 PM, Mateusz Kowalczyk
fuuze...@fuuzetsu.co.uk wrote:
 On 22/08/13 19:30, jabolo...@google.com wrote:
 Hi,

 I noticed Hayoo appears as a link in the toolbox of
 http://hackage.haskell.org and also that Hayoo seems to display better
 results than Hoogle.  For example, if you search for 'PublicKey' in
 Hayoo, you will get several results from Hackage libraries, such as,
 'crypto-pubkey' and 'crypto-api'.  However, the same query in Hoogle
 displays no results.

 Is Hayoo the default Hackage search engine ?
 Is Hoogle deprecated ?
 What the status ?

 You could also try the Hoogle hosted by FPComplete guys, it indexes more
 stuff.

Note that the 'normal' hoogle indexes all (?) of hackage. But by
default it only searches the haskell platform. You can add a package
with '+' to search in that package. E.g. PublicKey +crypto-api.

Regards,

Erik

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


Re: [Haskell-cafe] Alternative name for return

2013-08-15 Thread Erik Hesselink
On Thu, Aug 15, 2013 at 5:39 AM, Jason Dagit dag...@gmail.com wrote:
 Also, if anyone wants to look at prior art first, Idris supports applicative
 brackets.

As does she [0].

Erik

[0] https://personal.cis.strath.ac.uk/conor.mcbride/pub/she/idiom.html

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


Re: [Haskell-cafe] Value-weak hash tables in Haskell ?

2013-08-10 Thread Erik Hesselink
I'm not sure, but there are weak pointer [0], though I have never used them.

Erik

[0] 
http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-Weak.html

On Sat, Aug 10, 2013 at 7:13 PM, Aleksey Uymanov s9gf4...@gmail.com wrote:
 Hello, haskellers.

 Is there any package implementing magic hash tables weak in value? I
 mean when the value is garbage collected, then this key+value
 authomatically removes from the hash table.

 --
 Aleksey Uymanov s9gf4...@gmail.com

 ___
 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] deriving Data.HashTable - stack overflow

2013-08-08 Thread Erik Hesselink
There is a ticket with discussion and a patch here [0].

Erik

[0] http://ghc.haskell.org/trac/ghc/ticket/7633

On Thu, Aug 8, 2013 at 8:11 PM, David Thomas davidleotho...@gmail.com wrote:
 I do wish there was a compiler-checked way of specifying a minimum complete
 definition.


 On Thu, Aug 8, 2013 at 11:02 AM, Joey Adams joeyadams3.14...@gmail.com
 wrote:

 On Thu, Aug 8, 2013 at 12:22 PM, Lyle Kopnicky li...@qseep.net wrote:

 ...


 So I went to the Data.Hashable page and looked up examples on how to
 derive a Hashable instance for my datatype:

 http://hackage.haskell.org/packages/archive/hashable/latest/doc/html/Data-Hashable.html

 The problem occurs even when using the sample code on the page:


 {-# LANGUAGE DeriveGeneric #-}

  import GHC.Generics (Generic)
  import Data.Hashable

  data Colour = Red | Green | Blue
deriving Generic

  instance Hashable Colour

 If I then type `hash Red` I get a stack overflow.

 I am using the Haskell Platform, so I have hashable-1.1.2.5, but I notice
 the docs are for hashable-1.2.0.10. If I install 1.2.0.10 though, other code
 in my project breaks - seems like one part doesn't recognize the instances
 from another part. So I'll stick with the platform version.

 ...


 Generic support was added in hashable-1.2.  Before then, the default
 implementations for `hash` and `hashWithSalt` were written in terms of each
 other:

 hash = hashWithSalt defaultSalt
 hashWithSalt salt x = salt `combine` hash x

 Because you did not give an implementation for either of these, both
 default implementations were used, leading to a loop.

 ___
 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


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


Re: [Haskell-cafe] Alternative name for return

2013-08-06 Thread Erik Hesselink
What about `pure`? It's already used in applicative, and has the
motivation that it's embedding a pure value in some context. Since I
don't know the details of your project, I don't know if you need two
names (one for the applicative version, and one for the monadic
version).

Erik

On Tue, Aug 6, 2013 at 7:14 AM, J. Stutterheim j.stutterh...@me.com wrote:
 Dear Cafe,


 Suppose we now have the opportunity to change the name of the `return` 
 function in Monad, what would be a better  name for it? (for some 
 definition of better)

 N.B. I am _not_ proposing that we actually change the name of `return`. I do 
 currently have the opportunity to pick names for common functions in a 
 non-Haskell related project, so I was wondering if there perhaps is a better 
 name for `return`.


 - Jurriën
 ___
 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] Proposal: Non-recursive let

2013-07-31 Thread Erik Hesselink
On Fri, Jul 26, 2013 at 6:44 PM, Andreas Abel andreas.a...@ifi.lmu.de wrote:
   mapSnd f = (id *** f)

As a very small aside, this is just `second` from Control.Arrow.

Erik

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


Re: [Haskell-cafe] TH splicing and recompilation checking

2013-07-16 Thread Erik Hesselink
There is a GHC ticket about implementing a DEPENDS pragma for doing
this [0]. There are patches attached, but it looks like it isn't
finished yet.

Erik

[0] http://ghc.haskell.org/trac/ghc/ticket/4900

On Tue, Jul 16, 2013 at 7:41 PM, Johannes Waldmann
waldm...@imn.htwk-leipzig.de wrote:
 Hi.

 we are using template Haskell to splice in some code
 that is produced by reading and transforming the contents of another file.

 now, if this other file is touched (by editing),
 but not the main file, then ghc (and cabal) do not realize
 that the main file does need to be recompiled.

 is there a way to tell them about the dependency?

 (example main file:
 https://github.com/apunktbau/co4/blob/master/CO4/Test/Queens.hs)

 - J.W.



 ___
 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] Correct way to catch all exceptions

2013-07-10 Thread Erik Hesselink
Hi Michael,

We do this as well. In addition to AsyncException, we ignore
BlockedIndefinitelyOnSTM, BlockedIndefinitelyOnMVar and Deadlock. I'm
not sure you can ignore Timeout, since the type is not exported from
System.Timeout. I'm not sure how to classify these, though. They are
in some sense non-recoverable: restarting whatever the thread was
doing is not the right thing to do.

Erik

On Wed, Jul 10, 2013 at 8:28 AM, Michael Snoyman mich...@snoyman.com wrote:
 There's a pattern that arises fairly often: catching every exception thrown
 by code. The naive approach is to do something like:

 result - try someCode
 case result of
 Left (e :: SomeException) - putStrLn $ It failed:  ++ show e
 Right realValue - useRealValue

 This seems perfectly valid, except that it catches a number of exceptions
 which seemingly should not be caught. In particular, it catches the async
 exceptions used by both killThread and timeout.

 I think it's fair to say that there's not going to be a single function that
 solves all cases correctly, but it is a common enough situation that people
 need to write code that resumes work in the case of an exception that I
 think we need to either have some guidelines for the right approach here, or
 perhaps even a utility function along the lines of:

 shouldBeCaught :: SomeException - Bool

 One first stab at such a function would be to return `False` for
 AsyncException and Timeout, and `True` for everything else, but I'm not
 convinced that this is sufficient. Are there any thoughts on the right
 approach to take here?

 ___
 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] Correct way to catch all exceptions

2013-07-10 Thread Erik Hesselink
On Wed, Jul 10, 2013 at 10:39 AM, John Lato jwl...@gmail.com wrote:
 I think 'shouldBeCaught' is more often than not the wrong thing.  A
 whitelist of exceptions you're prepared to handle makes much more sense than
 excluding certain operations.  Some common whitelists, e.g. filesystem
 exceptions or network exceptions, might be useful to have.

You'd think that, but there are common use cases. For example, if you
have a queue of work items, and a thread (or threads) processing them,
it is useful to catch all exceptions of these threads. You can then
log the exception, remove the item from the queue and put it in some
error bucket, and continue on to the next item. The same goes for e.g.
socket listening threads etc.

The thing here is that you are *not* actually handling the specific
exception, but instead failing gracefully. But you still want to be
able to kill the worker threads, and you don't want to handle
exceptions that you cannot recover from even by moving on to the next
work item.

Erik

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


Re: [Haskell-cafe] newbie question about Functional dependencies conflict between instance declarations:.....

2013-07-05 Thread Erik Hesselink
The constraint on an instance never influences which instance is
selected. So as far as instance selection goes, 'instance Foo x' and
'instance C x = Foo x' are the same. The constraint is only checked
after the instance is selected.

Erik

On Fri, Jul 5, 2013 at 2:43 PM, Nicholls, Mark nicholls.m...@vimn.com wrote:
 Hello,



 I largely don’t know what I’m doing or even trying to do, it is a voyage
 into the unknown….but….if I go…



 {-# LANGUAGE MultiParamTypeClasses #-}

 {-# LANGUAGE FunctionalDependencies #-}

 {-# LANGUAGE FlexibleInstances #-}

 {-# LANGUAGE UndecidableInstances #-}



 class Foo x y | x - y, y - x

 instance Foo Integer Integer



 That seems to work….and my head seems to say…your created some sort of
 binary relation between 2 types…and made Integer,Integer a member of it…



 Something like that anyway….



 Then I go….



 data Bar



 instance Foo Bar x



 Error!but I’m think I understand this….I can’t claim that Bar,x is a
 member of Foo and Integer,Integer is member of Foo and preserve my
 functional dependencies, because Bar,Integer is now a member of Foo..



 Bad programmer…….





 So how I naively go….





 class NotAnInteger a



 instance (NotAnInteger x) = Foo Bar x



 I haven’t declared integer to be “NotAnInteger”….so (in a closed
 world)….this would seem to exclude the contradiction….but…





 Functional dependencies conflict between instance declarations:

   instance Foo Integer Integer -- Defined at liam1.lhs:7:12

   instance NotAnInteger x = Foo Bar x -- Defined at liam1.lhs:13:12



 So

 i)I clearly don’t understand something about the type
 system.

 ii)   I don’t know how to restrict type variables in
 instance declarations….i.e. how do I use the notion of “Foo” across
 different combinations of types, without them colliding.

















 CONFIDENTIALITY NOTICE

 This e-mail (and any attached files) is confidential and protected by
 copyright (and other intellectual property rights). If you are not the
 intended recipient please e-mail the sender and then delete the email and
 any attached files immediately. Any further use or dissemination is
 prohibited.

 While MTV Networks Europe has taken steps to ensure that this email and any
 attachments are virus free, it is your responsibility to ensure that this
 message and any attachments are virus free and do not affect your systems /
 data.

 Communicating by email is not 100% secure and carries risks such as delay,
 data corruption, non-delivery, wrongful interception and unauthorised
 amendment. If you communicate with us by e-mail, you acknowledge and assume
 these risks, and you agree to take appropriate measures to minimise these
 risks when e-mailing us.

 MTV Networks International, MTV Networks UK  Ireland, Greenhouse,
 Nickelodeon Viacom Consumer Products, VBSi, Viacom Brand Solutions
 International, Be Viacom, Viacom International Media Networks and VIMN and
 Comedy Central are all trading names of MTV Networks Europe.  MTV Networks
 Europe is a partnership between MTV Networks Europe Inc. and Viacom Networks
 Europe Inc.  Address for service in Great Britain is 17-29 Hawley Crescent,
 London, NW1 8TT.


 ___
 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] Catch multiple exceptions using 'Control.Exception'

2013-07-03 Thread Erik Hesselink
Perhaps you can use `catches` [0]?

Erik

[0] 
http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Exception.html#v:catches

On Wed, Jul 3, 2013 at 12:47 PM, Nikita Karetnikov
nik...@karetnikov.org wrote:
 I'm trying to update a package that uses 'Control.OldException' (works
 with GHC 6.10.4).  Here is a relevant (and simplified) part:

 import Control.OldException

 -- | A predicate matching synchronous exceptions.
 syncExceptions :: Exception - Maybe Exception
 syncExceptions (AsyncException _) = Nothing
 syncExceptions e  = Just e

 throwAsync :: IO a
 throwAsync = throwIO $ AsyncException StackOverflow

 throwArith :: IO a
 throwArith = throwIO $ ArithException DivideByZero

 'syncExceptions' is usually used like this:

 *Main tryJust syncExceptions throwArith
 Left divide by zero
 *Main tryJust syncExceptions throwAsync  -- pass through
 *** Exception: stack overflow

 The above doesn't work with GHC 7.6.3 because 'Control.OldException' [1]
 was removed.  And 'Control.Exception' doesn't have the 'Exception' type.

 Is there a way to adapt 'syncExceptions' to work with
 'Control.Exception'?

 [1] 
 http://hackage.haskell.org/packages/archive/base/4.1.0.0/doc/html/Control-OldException.html

 ___
 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] ANNOUNCE: haskell-names-0.1

2013-06-25 Thread Erik Hesselink
Tom Lokhorst and myself worked on a tool to generate missing imports,
both qualified and unqualified, at the Odessa hackathon. We created a
working proof of concept [0]. I wasn't aware of fix-imports.

Erik

[0] https://github.com/haskell-suite/halberd

On Tue, Jun 25, 2013 at 6:30 AM, Evan Laforge qdun...@gmail.com wrote:
 This is neat, it sounds like I could use this with fix-imports to find
 only modules that export the right function name, or even to add
 non-qualified imports.  But since it's already 95% good enough for my
 use case, I probably won't get around to it any time soon.

 On Thu, Jun 20, 2013 at 8:13 AM, Roman Cheplyaka r...@ro-che.info wrote:
 I am pleased to announce the first public release of haskell-names, a
 name resolution library for haskell-src-exts AST.

 Namely, it can do the following:

 *   for a module, compute its interface, i.e. the set of entities
 exported by the module, together with their original names.

 *   for each name in the module, figure out what it refers to — whether
 it's bound locally (say, by a where clause) or globally (and then
 give its origin).

 Thanks to haskell-packages, this library is fully integrated with Cabal,
 so that you can easily generate name interfaces for any Cabalized package.

 See more details in the README:
 http://documentup.com/haskell-suite/haskell-names

 This library is based on the code written by Lennart Augustsson in 2010.
 Little of that code survived, but nevertheless it's been a great help.

 Roman

 ___
 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

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


Re: [Haskell-cafe] Automating Hackage accounts

2013-06-13 Thread Erik Hesselink
On Thu, Jun 13, 2013 at 4:22 PM, Tobias Dammers tdamm...@gmail.com wrote:
 On Thu, Jun 13, 2013 at 05:07:38PM +0300, Mihai Maruseac wrote:
 On Thu, Jun 13, 2013 at 5:02 PM, Tobias Dammers tdamm...@gmail.com wrote:
  On Thu, Jun 13, 2013 at 09:44:03AM -0400, Andrew Pennebaker wrote:
  Could we add an HTML form for creating new Hackage accounts? Right now, 
  our
  community is small enough that emailing r...@soi.city.ac.uk and waiting 
  for
  a manual response isn't too bad of a problem, but as we grow, it would be
  nice for these sorts of things to be handled by a server, like with
  RubyGems and NPM.
 
  IMHO, a more pressing issue is SSL uploads and package signing. As it
  stands, anyone with a Hackage account can upload a new version of any
  given package, and some wire-sniffing is enough to reveal a legit user's
  password.

 I'd try to solve the latest two things first before going into
 creating a specific form.

 On the other hand, maybe we can rig something up with Yesod or similar
 to solve all three points at the same time. I'm busy now with my
 masters disertation but I can attempt something in a month if it seems
 ok and no one else does it before that date.

 IIRC, there have been previous attempts, or at least a discussion. I
 can't remember what the result was, though.

 Either way, it'll take more than just a Yesod web application built over
 a weekend; signed packages would require package authors to, well, sign,
 so cabal would need features for that; you'd also have to extend it to
 *check* those signatures, and give the user options to refuse or allow
 unsigned packages. SSL should be relatively simple though, mostly a
 matter of updating cabal's configuration and installing a suitable
 certificate on the hackage server.

There have been numerous discussions about this already. One of the
tricky things is that cabal uses the HTTP package for http calls, and
it doesn't support SSL. Adding it is non-trivial on windows, I
believe.

As for the user account creation and uploading packages you don't own,
Hackage 2 (any day now) has fixes for both.

Erik

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


Re: [Haskell-cafe] Automating Hackage accounts

2013-06-13 Thread Erik Hesselink
On Thu, Jun 13, 2013 at 4:48 PM, Niklas Hambüchen m...@nh2.me wrote:
 As for the user account creation and uploading packages you don't own,
 Hackage 2 (any day now) has fixes for both.

 Does Hackage 2 have SSL at least for the web interface?

I think it should be possible to set that up by proxying through e.g.
Apache. You have to be careful to open up all urls 'cabal' accesses
over http as well, but otherwise, I don't see a problem with that
setup. I'm not quite sure what it would achieve, though.

Erik

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


Re: [Haskell-cafe] Fwd: How to do automatic reinstall of all dependencies?

2013-04-25 Thread Erik Hesselink
I think --reinstall only reinstalls the package you are actually
installing, not the dependencies. You could try using a sandboxing
tool, like cabal-dev. Then you just do 'cabal-dev install', and when
you want to reinstall everything, you do 'rm cabal-dev/' to wipe the
sandbox and start over.

Regards,

Erik

On Thu, Apr 25, 2013 at 12:29 AM, capn.fre...@gmail.com
capn.fre...@gmail.com wrote:


 -db

 - Forwarded message -
 From: Captain Freako capn.fre...@gmail.com
 Date: Tue, Apr 23, 2013 9:21 pm
 Subject: How to do automatic reinstall of all dependencies?
 To: haskell-cafe@haskell.org

 Hi all,

 Does anyone know why the following is not working, as an automatic way of
 reinstalling all dependencies?:

 dbanas@dbanas-lap:~/prj/AMI-Tool$ cabal install --only-dependencies
 --reinstall --force-reinstalls parsec
 Resolving dependencies...
 All the requested packages are already installed:
 Use --reinstall if you want to reinstall anyway.
 dbanas@dbanas-lap:~/prj/AMI-Tool$

 Thanks,
 -db


 ___
 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] Fwd: [Haskell-beginners] Monad instances and type synonyms

2013-04-14 Thread Erik Hesselink
On Sun, Apr 14, 2013 at 9:28 AM, Chris Wong
chrisyco+haskell-c...@gmail.com wrote:
 On Sun, Apr 14, 2013 at 5:10 PM, Christopher Howard
 christopher.how...@frigidcode.com wrote:
 type Adjustment a = SaleVariables - a

 [...]

 instance Monad Adjustment where

   (=) = ...
   return = ...

 Essentially, you can't partially apply type synonyms. I don't recall
 the exact reasoning, but if this sort of thing was allowed it would
 probably poke funny holes in the type system.

 Also, Control.Monad.Instances already supplies a Monad instance for
 functions (r - a). So even if that did pass, you'd bump into
 overlapping instances anyway.

The fact that that instance exists shows that you can define an
instance like this (even though you don't have to, since it already
exists). The trick is to define the type synonym partially applied.
When you do that, you can define the instance:

type Adjustment = (-) SaleVariables
instance Monad Adjustment where

Note that this needs the extensions TypeSynonymInstances and FlexibleInstances.

Erik.

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


Re: [Haskell-cafe] A question about data declaration

2013-03-21 Thread Erik Hesselink
You could use a GADT:

{-# LANGUAGE GADTs #-}

data T a where
  C1 :: Int - T Int
  C2 :: Char - T Char
  C3 :: T Char - T Char

This will allow you to put a C3 in a C3. If you want to prevent that,
just invent some other index, something like:

{-# LANGUAGE GADTs, EmptyDataDecls #-}

data Yes
data No

data T a where
  C1 :: Int - T No
  C2 :: Char - T Yes
  C3 :: T Yes - T No

Not sure if this is a *better* way though. Your initial solution is
also ok, I guess.

Regards,

Erik

On Thu, Mar 21, 2013 at 1:48 PM, C K Kashyap ckkash...@gmail.com wrote:
 Hi,

 I have a situation where I need to define a data type T such that

 data T = C1 Int | C2 Char | C3 T

 However, I want to enforce a constraint that C3 only allows (C2 Char) and
 not (C1 Int). That is

 x = C3 (C1 10) -- should not compile - but my above definition will let it
 compile


 I was thinking of this -

 data C1 = C1 Int
 data C2 = C2 Char
 data T = TC1 C1 | TC1 C2 | TC3 C2

 Is there a better way to do it?

 Regards,
 Kashyap

 ___
 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] How does one create an input handle bound to a string instead of a file?

2013-02-28 Thread Erik Hesselink
Is your parser impure? I would expect a function from
String/Text/ByteString to Maybe (SExpr Pos).
 Then you have no need for a Handle.

Regards,

Erik

On Thu, Feb 28, 2013 at 2:32 PM, John D. Ramsdell ramsde...@gmail.com wrote:
 I think I wasn't clear about my question.  I want something that
 creates a value of type System.IO.Handle.  You see, I have a high
 performance S-expression parser that I'd like to use in GHCi reading
 strings while at the command loop.

 Here is more details on my module SExpr that exports the SExpr data
 type and the load function.  The desired function is called
 stringHandle.

 -- An S-expression
 data SExpr
 = S String -- A symbol
 | Q String -- A quoted string
 | N Int-- An integer
 | L [SExpr a]  -- A proper list

 -- Read one S-expression or return Nothing on EOF
 load :: Handle - IO (Maybe (SExpr Pos))

 In GHCi, I want to type something like:

 SExpr let h = stringHandle ()
 SExpr load h
 Just (L [])
 SExpr load h
 Nothing
 SExpr

 It seems to me right now that I have to implement a duplicate parser
 that implements Read.  At least S-expression parsing is easy.

 John

 On Thu, Feb 28, 2013 at 3:02 AM, Ganesh Sittampalam gan...@earth.li wrote:
 Hi,

 On 27/02/2013 20:38, John D. Ramsdell wrote:
 How does one create a value of type System.IO.Handle for reading that
 takes its input from a string instead of a file?  I'm looking for the
 equivalent of java.io.StringReader in Java.  Thanks in advance.

 http://hackage.haskell.org/package/bytestring-handle can make handles
 that read and write to ByteStrings.

 Cheers,

 Ganesh



 ___
 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] ANN: Nomyx 0.1 beta, the game where you can change the rules

2013-02-27 Thread Erik Hesselink
Note that cookies are not the solution here. Cookies are just as user
controlled as the url, just less visible. What you need is a session
id: a mapping from a non-consecutive, non-guessable, secret token to
the user id (which is sequential and thus guessable, and often exposed
in urls etc.). It doesn't matter if you then store it in the url or a
cookie. Cookies are just more convenient.

Erik

On Wed, Feb 27, 2013 at 3:30 PM, Corentin Dupont
corentin.dup...@gmail.com wrote:
 Yes, having a cookie to keep track of the session if something I plan to do.

 On Wed, Feb 27, 2013 at 3:16 PM, Mats Rauhala mats.rauh...@gmail.com
 wrote:

 The user id is not necessarily the problem, but rather that you can
 impose as another user. For this, one solution is to keep track of a
 unique (changing) user token in the cookies and use that for verifying
 the user.

 --
 Mats Rauhala
 MasseR

 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.4.10 (GNU/Linux)

 iEYEARECAAYFAlEuFVQACgkQHRg/fChhmVMu3ACeLLjbluDQRYekIA2XY37Xbrql
 tH0An1eQHrLLxCjHHBQcZKmy1iYxCxTt
 =tf0d
 -END PGP SIGNATURE-


 ___
 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


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


Re: [Haskell-cafe] How to input Unicode string in Haskell program?

2013-02-21 Thread Erik Hesselink
You can also set the locale encoding for a handle (e.g.
System.IO.stdin) from code using `System.IO.hSetEncoding` [0].

Erik

[0] 
http://hackage.haskell.org/packages/archive/base/latest/doc/html/System-IO.html#v:hSetEncoding

On Thu, Feb 21, 2013 at 12:07 PM, Alexander V Vershilov
alexander.vershi...@gmail.com wrote:
 The problem is that Prelude.getLine uses current locale to load characters:
 for example if you have utf8 locale, then everything works out of the box:

 $ runhaskell 1.hs
 résumé 履歴書 резюме
 résumé 履歴書 резюме

 But if you change locale you'll have error:

 LANG=C runhaskell 1.hs
 résumé 履歴書 резюме
 1.hs: stdin: hGetLine: invalid argument (invalid byte sequence)

 To force haskell use UTF8 you can load string as byte sequence and convert
 it to UTF-8
 charecters for example by

 import qualified Data.ByteString as S
 import qualified Data.Text.Encoding as T

 main = do
 x - fmap T.decodeUtf8 S.getLine

 now code will work even with different locale, and you'll load UTF8 from
 shell
  independenty of user input's there

 --
 Alexander


 On 21 February 2013 13:58, Semyon Kholodnov joker...@gmail.com wrote:

 Imagine we have this simple program:

 module Main(main) where

 main = do
 x - getLine
 putStrLn x

 Now I want to run it somehow, enter résumé 履歴書 резюме and see this
 string printed back as résumé 履歴書 резюме. Now, the first problem is
 that my computer runs Windows, which means that I can't use ghci
 :main or result of ghc main.hs to enter such an outrageous string
 — Windows console is locked to one specific local code page, and no
 codepage contains Latin-1, Cyrillic and Kanji symbols at the same
 time.

 But there is also WinGHCi. So I do :main, copy-paste this string
 into the window (It works! Because Windows has Unicode for 20 years
 now), but the output is all messed up. In a rather curious way,
 actually: the input string is converted to UTF-8 byte string, and its
 bytes are treated as being characters from my local code page.

 So, it appears that I have no way to enter Unicode strings into my
 Haskell programs by hands, I should read them from files. That's sad,
 and I refuse to think I am the first one with such a problem, so I
 assume there is a solution/workaround. Now would someone please tell
 me this solution? Except from Just stick to 127 letters of ASCII, of
 course.

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




 --
 Alexander

 ___
 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] How far compilers are allowed to go with optimizations?

2013-02-06 Thread Erik Hesselink
On Wed, Feb 6, 2013 at 1:18 PM, Austin Seipp mad@gmail.com wrote:
 Now, on a slight tangent, in practice, I guess it depends on your
 target market. C programs don't necessarily expose the details to make
 such rich optimizations possible. And Haskell programmers generally
 rely on optimizations to make order of magnitude performance
 difference in constant factors, although perhaps not in direct big-O
 terms (and no, this isn't necessarily bad)

I think some GHC optimizations do change at least space usage, even in
big-O terms. For example, strictness analysis can make folds go from
O(n) to O(1) space, I think.

Regards,

Erik

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


Re: [Haskell-cafe] hxt pickling question

2013-01-24 Thread Erik Hesselink
There's showPickled [0] and unpickleDoc [1], maybe those help?

Erik

[0] 
http://hackage.haskell.org/packages/archive/hxt/latest/doc/html/Text-XML-HXT-Arrow-Pickle-Xml.html#v:showPickled
[1] 
http://hackage.haskell.org/packages/archive/hxt/latest/doc/html/Text-XML-HXT-Arrow-Pickle-Xml.html#v:unpickleDoc

On Thu, Jan 24, 2013 at 4:40 PM,  bri...@aracnet.com wrote:
 Hi,

 Trying to understand how to write a document using a pickler but I can't make 
 sense of the types.

 From the example:

  runX ( xunpickleDocument xpSeason
[ withValidate no
, withTrace 1
, withRemoveWS yes
, withPreserveComment no
] simple2.xml
  
  processSeason
  
  xpickleDocument   xpSeason
[ withIndent yes
] new-simple2.xml
)

 So all I want to do is pickle a value directly instead of reading the value 
 from a document.  I expected to do something like:

 runX (someHXTPicklingFunction myValue
   
   xpickleDocument ...)


 but I can't seem to figure out what someHXTPicklingFunction should be, it's 
 certainly nothing obvious like pickleDoc, because that generates the wrong 
 value.

 Seems like I probably have a much more fundamental problem in that I really 
 don't understand how the arrow part of this little example really works, but 
 I was kind of hoping that doing something simple like this might shed some 
 light on that.  And then was immediately stuck in type hell.


 Thanks,

 Brian


 ___
 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] How to disable document in .cabal file?

2013-01-16 Thread Erik Hesselink
You could do what I do: create an alias in bash. I have in my ~/.bashrc:

alias ciq='cabal install --disable-documentation
--disable-library-profiling --disable-executable-profiling'

The alias 'ciq' stands for 'cabal install quick' and disables things I
don't need during development, but do slow down the build.

Regards,

Erik

On Wed, Jan 16, 2013 at 3:10 AM, Magicloud Magiclouds
magicloud.magiclo...@gmail.com wrote:
 So the only way is to use param every time I build this certain project?
 Really hoping I could disable it in project.cabal 


 On Wed, Jan 16, 2013 at 6:45 AM, Albert Y. C. Lai tre...@vex.net wrote:

 On 13-01-15 12:06 AM, Magicloud Magiclouds wrote:

I have enabled document in .cabal/config, so I could get document
 every time I installed libraries or so.
But when I compile my own applications, it also takes time on
 generating non-exist documents. How to disable it just for this project?


 If cabal install: add --disable-documentation.
 See also cabal install --help.

 If cabal configure and cabal build etc: nothing to do, just omit
 cabal haddock.


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




 --
 竹密岂妨流水过
 山高哪阻野云飞

 And for G+, please use magiclouds#gmail.com.

 ___
 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] Example programs with ample use of deepseq?

2013-01-11 Thread Erik Hesselink
On Wed, Jan 9, 2013 at 11:38 PM, Joachim Breitner
m...@joachim-breitner.de wrote:
 Am Mittwoch, den 09.01.2013, 15:11 +0100 schrieb Erik Hesselink:
 We finally solved the problems by completely moving
 to strict map operations, strict MVar/TVar operations, and strict data
 types.

 do you mean strict by policy (i.e. before storing something in a
 [MT]Var, you ensure it is evaluated) or by construction (by `seq` or
 `deepseq`’ing everything before it is stored)? In the latter case: Seq
 or deeqseq? Again in the latter case: Do you worry about the performance
 of repeatedly deepseq’ing an already deepseq’ed and possibly large
 value?

Strict by construction: we `seq` when storing in a var. This is
similar to the primed functions in some places, and the new
Data.Map.Strict. So repeatedly deepseq'ing isn't a problem: deepseq in
our case is only used for debugging.

 You are not the first user of Haskell who ends up with that approach to
 lazy evaluation. I’m not sure what that means for Haskell, though.

Well, we still use the 'normal' lazy approach in most places. Only
where we have persistent shared state do we use the above approach of
making everything strict. This means updaters pay the computational
price, not readers, which seems like a sane idea.

Regards,

Erik

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


Re: [Haskell-cafe] Example programs with ample use of deepseq?

2013-01-09 Thread Erik Hesselink
On Tue, Jan 8, 2013 at 10:54 PM, Joachim Breitner
m...@joachim-breitner.de wrote:
 Am Dienstag, den 08.01.2013, 13:01 -0800 schrieb Evan Laforge:
  surprisingly, deepseq is not used as much as I thought.
  http://packdeps.haskellers.com/reverse/deepseq lists a lot of packages,
  but (after grepping through some of the code) most just define NFData
  instances and/or use it in tests, but rarely in the „real“ code. For
  some reason I expected it to be in more widespread use.

 I've been using deepseq quite a bit lately, but for the purpose of
 debugging space leaks.  If, when I deepseq a big structure, the space
 leak goes away, I can then apply it to some subset.  After much
 trial-and-error I can find something which is insufficiently strict.
 Ideally I can then strictify that one thing and stop using the
 deepseq.  I wish there was a more efficient way to do this.

 this is also a possible application of my approach, by providing a „I
 want this data structure to be fully evaluated now, please tell me how
 it currently looks, i.e. where in the data structure still thunks lie
 hidden.“

 Do you have a nice, striking example where using your approach (using
 deepseq and comparing efficiency) you could make a difference, and where
 a tool as described above would make the analysis much easier?

We've also used this approach to debug space-leaks, and would have
loved such a tool. We used deepseq, and compared the heap profiles. We
finally found the leaks this way, and fixed them using strictness
annotations. Finally, we verified by running deepseq again at top
level and observing that it didn't change anything anymore.

Erik

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


Re: [Haskell-cafe] Example programs with ample use of deepseq?

2013-01-09 Thread Erik Hesselink
On Wed, Jan 9, 2013 at 2:40 PM, Joachim Breitner
m...@joachim-breitner.de wrote:
 Hi Erik,

 Am Mittwoch, den 09.01.2013, 14:23 +0100 schrieb Erik Hesselink:
 We've also used this approach to debug space-leaks, and would have
 loved such a tool. We used deepseq, and compared the heap profiles. We
 finally found the leaks this way, and fixed them using strictness
 annotations. Finally, we verified by running deepseq again at top
 level and observing that it didn't change anything anymore.

 same question to you: Would you have a suitable test case that can be
 used to test and demonstrate the usefulness of such tools?

Sadly, no. This is a private, core part of our application that I
cannot share. I can describe what we did, and also the structure of
the data in broad terms: we have several Maps, where the keys are
usually Text, and the values are custom data types. These contain keys
into these maps again. The whole thing defines a graph with several
indexes into it. We finally solved the problems by completely moving
to strict map operations, strict MVar/TVar operations, and strict data
types.

If you have more questions, or tools you want to test, I'd be happy to
help, though.

Regards,

Erik

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


Re: [Haskell-cafe] Equality test between types that returns type-level Bool ?

2012-11-26 Thread Erik Hesselink
If you're up for it, Oleg has a lot of interesting material about this
subject [1].

Regards,

Erik

[1] http://okmij.org/ftp/Haskell/typeEQ.html


On Sun, Nov 25, 2012 at 9:36 AM, Takayuki Muranushi muranu...@gmail.comwrote:

 Is it possible to write

 type family SameType a b :: Bool

 which returns True if a and b are the same type, and False otherwise?

 I encountered this problem when I was practicing promoted lists and
 tuples in ghc-7.6.1. One of my goal for practice is to write more
 modular version of extensible-dimensional calculations, and to
 understand whether ghc-7.6.1 is capable of it.


 http://hackage.haskell.org/packages/archive/dimensional/0.10.2/doc/html/Numeric-Units-Dimensional-Extensible.html

 Some of my attempts:

 https://github.com/nushio3/dimensional-tf/blob/master/attic/list-02.hs
 This fails because :==: is not an equality test between a and b, but
 is a equality test within a (promoted) kind.

 https://github.com/nushio3/dimensional-tf/blob/master/attic/list-03.hs
 This fails because type instance declarations are not read from top to
 bottom. (not like function declarations.)

 https://github.com/nushio3/dimensional-tf/blob/master/attic/map-03.hs
 I could define a lookup using class constraints, but when I use it,
 results in overlapping instances.

 So, will somebody teach me which of the following is correct?

 * We can write a type family SameType a b :: Bool
 * We cannot do that because of theoretical reason (that leads to
 non-termination etc.)
 * We cannot write SameType, but there are ways to write functions like
 'filter' and 'merge' , over type-level lists, without using SameType.

 Always grateful to your help,
 --
 Takayuki MURANUSHI
 The Hakubi Center for Advanced Research, Kyoto University
 http://www.hakubi.kyoto-u.ac.jp/02_mem/h22/muranushi.html

 ___
 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] How to determine correct dependency versions for a library?

2012-11-14 Thread Erik Hesselink
On Wed, Nov 14, 2012 at 10:57 AM, Roman Cheplyaka r...@ro-che.info wrote:

 * Ivan Lazar Miljenovic ivan.miljeno...@gmail.com [2012-11-14
 20:53:23+1100]
  Doesn't this prevent the error of this package won't build (even if
  the error message doesn't precisely say that)?

 Yeah, it replaces one error with another. How is it supposed to help me
 if I really want to build this package? Instead of fixing just the code,
 I now have to fix the cabal file as well!


The error might be clearer, since it comes up right away, and points you to
the right package, together with the reason (doesn't support the right base
version).

If it started to build instead, it might fail in the middle, with some
error that you might not know is caused by changes in base.

But the question comes down to numbers: how often do packages break with
new base versions, how soon do people need to be able to use the new GHC
without changing other packages, etc. Some might argue that packages
'usually' work, so we should leave out upper bounds, even if it gives worse
errors. Others say the errors are so bad, or badly timed, that we should
have upper bounds, and the work for maintainers, while greater, is not too
large. I know what I think, but nobody has concrete numbers about breakages
with new base versions, amount of time spent updating packages, unupdated
packages etc. Some can be found with a grep over the hackage tarball, but
most can't.

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


Re: [Haskell-cafe] local type denotation

2012-11-14 Thread Erik Hesselink
You need to enable ScopedTypeVariables, and add a forall to introduce the
type variable at the top level. The local variable will then be the *same*
'a' instead of a fresh one:

  {-# LANGUAGE ScopedTypeVariables #-}

  data D a = D1 a | D2 a (a - a)

  f :: forall a. Eq a = D a - a
  f (D1 x)   = x
  f (D2 x g) = let y :: Eq a = a
   y = g x
   in  if x == y then x else g y

  main = putStr $ shows (f (D2 (1 :: Int) succ)) \n


On Wed, Nov 14, 2012 at 1:03 PM, Serge D. Mechveliani mech...@botik.ruwrote:

 Please,
 how to correctly set an explicit type for a local value in the body of
 a polymorphic function?

 Example (tested under  ghc-7.6.1):

   data D a = D1 a | D2 a (a - a)

   f :: Eq a = D a - a
   f (D1 x)   = x
   f (D2 x g) = let -- y :: Eq a = a
y = g x
in  if x == y then x else g y

   main = putStr $ shows (f (D2 (1 :: Int) succ)) \n


 This is compiled byghc --make Main

 Now I need, for a certain reason, to explicitly set the type for  y  in
 `let',  with the meaning:
 this very `a' which is in the signature for  f
 (and I think that this type Haskell assignes to  y  in  y = g x).

 I need to declare this type in a separate line:  y :: what ever it is.

 Both  `y :: a'  and  `y :: Eq a = a'  are not compiled.

 Please, copy the answer to  mech...@botik.ru

 Thanks,

 --
 Sergei

 ___
 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] How to determine correct dependency versions for a library?

2012-11-12 Thread Erik Hesselink
tl;dr: Breakages without upper bounds are annoying and hard to solve for
package consumers. With upper bounds, and especially with sandboxes,
breakage is almost non-existent.

I don't see how things break with upper bounds, at least in the presence of
sandboxes. If all packages involved follow the PVP, a build that worked
once, will always work. Cabal 0.10 and older had problems here, but 0.14
and later will always find a solution to the dependencies if there is one
(if you set max-backjumps high enough).

Without sandboxes, cabal might have to reinstall a package with different
dependencies, breaking other packages. It will currently warn against this.
Future versions will hopefully tell you about the sandboxing features that
can also be used to avoid this.

In contrast, without upper bounds a packages is almost sure to fail to
compile at some point. A user will then get compile errors outside his own
code, somewhere in the middle of his dependency chain. Depending on his
expertise, this will be either hard or impossible to fix. In particular, it
is not clear that too lenient dependencies are the problem, and if it is
clear, you do not know which ones.

So I still see this as a tradeoff between the interests of package
developers/maintainers (upper bounds give more testing/release work, and
also, they want to use the latest versions) versus package users/companies
(who want a build to work, but often don't care about the bleeding edge).

Personnaly, I fall in both groups, and have experienced both problems. At
Silk, we have (internal) packages with huge dependency chains (we depend on
both happstack and snap). With cabal 0.10, this was a nightmare. Since
0.14, we've had no breakages, except from packages that do not specify
upper bounds! We're fairly up-to-date with GHC versions: we're on 7.4 now,
but with no immediate plans to switch to 7.6. Switching to a new GHC
version is a bit of work, but we can decide when to do the work. Without
upper bounds, our builds can break at any moment, and we have to fix it
then and there to be able to continue working.

If you do have to use the bleeding edge (or a packages uses really outdated
dependencies) you can also use sandboxes to your advantage. Just 'cabal
unpack' the problematic package, change the dependencies and add the
resulting source package to your sandbox. This is what we do when we test
out a new GHC version. We also try to contribute fixes back upstream.

This is why I ask for people to specify upper bounds. They mean that
packages keep working, and they prevent users from getting
incomprehensible, badly timed build failures.

Erik


On Sat, Nov 10, 2012 at 5:16 PM, Roman Cheplyaka r...@ro-che.info wrote:

 * Erik Hesselink hessel...@gmail.com [2012-11-10 16:40:30+0100]
  On Fri, Nov 9, 2012 at 5:52 PM, Roman Cheplyaka r...@ro-che.info
 wrote:
 
   * Janek S. fremenz...@poczta.onet.pl [2012-11-09 17:15:26+0100]
but I am aware that if the library were to be released on Hackage I
would have to supply version numbers in the dependencies. The
 question
is how to determine proper version numbers?
  
   With the current state of affairs, your best bet is not to specify any
   version bounds, or specify only lower ones.
  
   Upper version bounds much more often break things that fix things.
  
 
  I'd like to ask people not to do this. What you're doing then is moving
 the
  burden from the maintainer (who has to test with new versions and relax
  dependencies) to the users of the library (who will be faced with
 breakages
  when new incompatible dependencies are released).

 The trouble is, when things break, they break either way — so I simply
 propose to reduce the probability of things breaking.

 I know, I know, the theory is that Cabal magically installs the right
 versions for you. However, in practice it often can't do that due to
 various reasons (base libraries, package reinstalls etc.)

 I'm not trying to shift the burden from the maintainer — I simply know
 from experience that maintainers are not nearly as quick and responsible
 as would be required for such scheme to work, so as a *user* I'd prefer
 that they omit upper bounds — at least until the --ignore-constraints
 option is implemented.
 (https://github.com/haskell/cabal/issues/949)

 Roman

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


Re: [Haskell-cafe] How to determine correct dependency versions for a library?

2012-11-12 Thread Erik Hesselink
On Mon, Nov 12, 2012 at 5:13 PM, Johan Tibell johan.tib...@gmail.comwrote:

 On Mon, Nov 12, 2012 at 1:06 AM, Erik Hesselink hessel...@gmail.comwrote:

 tl;dr: Breakages without upper bounds are annoying and hard to solve for
 package consumers. With upper bounds, and especially with sandboxes,
 breakage is almost non-existent.

 I don't see how things break with upper bounds, at least in the presence
 of sandboxes. If all packages involved follow the PVP, a build that worked
 once, will always work. Cabal 0.10 and older had problems here, but 0.14
 and later will always find a solution to the dependencies if there is one
 (if you set max-backjumps high enough).


 The breakage people are talking about with regards to upper bounds is
 that every time a new version of a dependency comes out, packages with
 upper bounds can't compile with it, even if they would without the upper
 bound. For example, the version number of base is bumped with almost every
 GHC release, yet almost no packages would actually break to the changes
 that caused that major version number to go up.


Yes, this is why I talk about living on the bleeding edge, and shifting the
burden from package maintainers to package users.

And I believe the last base changes included a change to 'catch' which
would have broken a lot of packages. The Num changes also caused a lot of
code changes, and there were probably more I don't remember.

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


Re: [Haskell-cafe] How to determine correct dependency versions for a library?

2012-11-10 Thread Erik Hesselink
On Fri, Nov 9, 2012 at 5:52 PM, Roman Cheplyaka r...@ro-che.info wrote:

 * Janek S. fremenz...@poczta.onet.pl [2012-11-09 17:15:26+0100]
  but I am aware that if the library were to be released on Hackage I
  would have to supply version numbers in the dependencies. The question
  is how to determine proper version numbers?

 With the current state of affairs, your best bet is not to specify any
 version bounds, or specify only lower ones.

 Upper version bounds much more often break things that fix things.


I'd like to ask people not to do this. What you're doing then is moving the
burden from the maintainer (who has to test with new versions and relax
dependencies) to the users of the library (who will be faced with breakages
when new incompatible dependencies are released).

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


Re: [Haskell-cafe] [Security] Put haskell.org on https

2012-10-28 Thread Erik Hesselink
While I would love to have hackage available (or even forced) over
https, I think the biggest reason it currently isn't, is that cabal
would then also need https support. This means the HTTP library would
need https support, which I've heard will be hard to implement
cross-platform (read: on Windows).

However, I guess providing https as an option is still a huge step
forwards compared to the current situation.

Erik

On Sun, Oct 28, 2012 at 1:20 AM, Niklas Hambüchen m...@nh2.me wrote:
 (I have mentioned this several times on #haskell, but nothing has
 happened so far.)

 Are you aware that all haskell.org websites (hackage, HaskellWiki, ghc
 trac) allow unencrypted http connections only?

 This means that everyone in the same Wifi can potentially

 - read you passwords for all of these services

 - abuse your hackage account and override arbitrary packages
   (especially since hackage allows everybody to override everything)


 I propose we get an SSL certificate for haskell.org.
 I also offer to donate that SSL certificate (or directly create it using
 my Startcom account).

 Niklas

 ___
 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] [Security] Put haskell.org on https

2012-10-28 Thread Erik Hesselink
I think it is only needed for 'cabal upload'. So if you upload via the
web only, you'd never send your password over plain HTTP.

Erik

On Sun, Oct 28, 2012 at 1:38 PM, Petr P petr@gmail.com wrote:
   Erik,

 does cabal need to do any authenticated stuff? For downloading
 packages I think HTTP is perfectly fine. So we could have HTTP for
 cabal download only and HTTPS for everything else.

   Best regards,
   Petr Pudlak

 2012/10/28 Erik Hesselink hessel...@gmail.com:
 While I would love to have hackage available (or even forced) over
 https, I think the biggest reason it currently isn't, is that cabal
 would then also need https support. This means the HTTP library would
 need https support, which I've heard will be hard to implement
 cross-platform (read: on Windows).

 However, I guess providing https as an option is still a huge step
 forwards compared to the current situation.

 Erik

 On Sun, Oct 28, 2012 at 1:20 AM, Niklas Hambüchen m...@nh2.me wrote:
 (I have mentioned this several times on #haskell, but nothing has
 happened so far.)

 Are you aware that all haskell.org websites (hackage, HaskellWiki, ghc
 trac) allow unencrypted http connections only?

 This means that everyone in the same Wifi can potentially

 - read you passwords for all of these services

 - abuse your hackage account and override arbitrary packages
   (especially since hackage allows everybody to override everything)


 I propose we get an SSL certificate for haskell.org.
 I also offer to donate that SSL certificate (or directly create it using
 my Startcom account).

 Niklas

 ___
 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

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


Re: [Haskell-cafe] ANN: cabal-install-1.16.0 (and Cabal-1.16.0.1)

2012-10-03 Thread Erik Hesselink
On Wed, Oct 3, 2012 at 6:06 PM, Johan Tibell johan.tib...@gmail.com wrote:
 On the behalf of the many contributors to cabal, I'm proud to present
 cabal-install-1.16.0.

Congratulations and thanks to all those involved!

 To install:

 cabal update
 cabal install cabal-install-1.16.0 Cabal-1.16.0.1

It seems that hackage no longer has a preferred-version for cabal, so
that a simple 'cabal update  cabal install cabal-install' will do
the trick. Was this intentional? With 0.14, it took quite a while for
it to become the preferred version.

Erik

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


Re: [Haskell-cafe] Copying a syntax tree

2012-10-02 Thread Erik Hesselink
You could add {-# LANGUAGE DeriveFunctor #-}, and then add 'deriving
Functor' to all your data types (or you could of course manually
define your functor instances). Then what you want is just 'fmap
show'.

Erik

On Tue, Oct 2, 2012 at 9:55 AM, Sergey Mironov ier...@gmail.com wrote:
 Hi! I have a syntax tree defined like this:


 data A a = A Int Int (B a)

 data B a = B String String (C a)

 data C a = C Int Int (D a)


 and so on, all the data are parametrized with a type variable. This variable
 is actually used as a field in the very end of a hierarchy:


 data D a = D Int a


 Now I have to write a function which would copy (A Int) to (A String). Is it
 possible to do so using TH/syb without writing

 copyA (A i1 i2 b) = A i1 i2 (copyB b)
 copyB = ...
 copyC = ...
 ..
 copyD (D i a) = D i (show a)
 ?

 Could you provide me with a hint?

 Thanks,
 Sergey

 ___
 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] 64-bit vs 32-bit haskell platform on Mac: misleading notice on Platform website?

2012-09-26 Thread Erik Hesselink
On Wed, Sep 26, 2012 at 10:58 AM, Johan Tibell johan.tib...@gmail.com wrote:
 On Wed, Sep 26, 2012 at 7:44 AM, Carter Schonwald
 carter.schonw...@gmail.com wrote:
 To the best of my knowledge there is absolutely no reason to use the 32bit
 haskell on OS X (aside from memory usage optimization cases which likely do
 not matter to the *typical* user), and the community should probably update
 the recommendation to reflect this.

 The source of the recommendation are the benchmark results presented here:

 http://mtnviewmark.wordpress.com/2011/12/07/32-bits-less-is-more/

 The problem of missing 32-bit C libraries might be a good reason for
 us to recommend 64-bit though and leave the 32-bit recommendation to
 people who know what they are doing.

We switched to a 64bit GHC recently for this exact reason. The 64bit
libraries are either already installed, or can easily be installed
through e.g. brew. For 32bit libraries, we sometimes had to compile
from source, passing all kinds of flags. The downside for us is
doubling the memory usage, but that's more easily solved (with more
memory). I haven't noticed the performance reduction.

So in short, I think the 64bit version should be the default
recommendation on OS X.

Erik

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


Re: [Haskell-cafe] Transforming a ADT to a GADT

2012-09-14 Thread Erik Hesselink
On Fri, Sep 14, 2012 at 2:01 PM, Sean Leather leat...@cs.uu.nl wrote:
 On Fri, Sep 14, 2012 at 12:45 PM, Florian Lorenzen wrote:

 I'd like to transform a value of an ADT to a GADT. Suppose I have the
 simple expression language

  data Exp = Lit Int  | Succ Exp  | IsZero Exp  | If Exp Exp Exp

 and the GADT

  data Term t where  TLit :: Int - Term Int  TSucc :: Term Int -
 Term Int  TIsZero :: Term Int - Term Bool  TIf :: Term Bool - Term
 ty - Term ty - Term ty

 that encodes the typing rules.

 Now, I'd like to have a function

  typecheck :: Exp - Maybe (Term t)  typecheck exp = ...

 that returns the GADT value corresponding to `exp' if `exp' is type
 correct.


 It's not pretty, but it should still be safe...

 import Control.Applicative
 import Unsafe.Coerce

 tcInt :: Exp - Maybe (Term Int)
 tcInt (Lit i)   = pure (TLit i)
 tcInt (Succ e)  = TSucc $ tcInt e
 tcInt (If c e1 e2)  = TIf $ tcBool c * tcInt e1 * tcInt e2
 tcInt _ = empty

 tcBool :: Exp - Maybe (Term Bool)
 tcBool (IsZero e)   = TIsZero $ tcInt e
 tcBool (If c e1 e2) = TIf $ tcBool c * tcBool e1 * tcBool e2
 tcBool _= empty

 typecheck :: Exp - Maybe (Term t)
 typecheck e = forget $ tcInt e | forget $ tcBool e
   where
 forget :: Term a - Term b
 forget = unsafeCoerce

I don't think this is safe. What will happen if you evaluate
  typecheck (Lit 1) :: Maybe (Term Bool)

In general, I think you have to work inside an existential. So you
hide the type of the parsed Term inside an existential. If you want to
apply functions to this Term, you unpack, call the function, and
repack.

I don't think there's a way around this, since the type parameter to
Term _is_ existential. You know there is some type, but you don't know
what it is. If you make it polymorphic, the _called_ can choose it,
which is the opposite of what you want.

Erik

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


Re: [Haskell-cafe] Transforming a ADT to a GADT

2012-09-14 Thread Erik Hesselink
On Fri, Sep 14, 2012 at 2:27 PM, Erik Hesselink hessel...@gmail.com wrote:
 In general, I think you have to work inside an existential. So you
 hide the type of the parsed Term inside an existential. If you want to
 apply functions to this Term, you unpack, call the function, and
 repack.

Maybe I should expand what I mean by this. Let's say you have:

  data SomeTerm where
SomeTerm :: Term a - SomeTerm

Your typecheck function goes:

typecheck :: Exp - SomeTerm

and you want to apply:

transform :: Term t - Term t

You should do something like:

f (SomeTerm t) = SomeTerm (transform t)

Or, more generally:

onSomeTerm :: (forall t. Term t - Term t) - SomeTerm - SomeTerm
onSomeTerm f (SomeTerm t) =  SomeTerm (f t)

Erik

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


Re: [Haskell-cafe] How Type inference work in presence of Functional Dependencies

2012-09-13 Thread Erik Hesselink
I don't know if this is a bug or not, but the translation to type
families works:

class Foo a where
  type FooT a :: *

instance Foo Int where
  type FooT Int = Float

f :: Int - FooT Int
f = undefined

g :: Int - Float
g = undefined

h :: Int - FooT Int
h = g

You don't even need the class contexts.

Erik

On Thu, Sep 13, 2012 at 11:18 AM, satvik chauhan
mystic.sat...@gmail.com wrote:
 Consider the code below :

 {-# LANGUAGE
 MultiParamTypeClasses,FlexibleInstances,FunctionalDependencies,UndecidableInstances,FlexibleContexts
 #-}
 class Foo a c | a - c
 instance Foo Int Float
 f :: (Foo Int a) = Int - a
 f = undefined

 Now when I see the inferred type of f in ghci

 :t f

 f :: Int - Float

 Now If I add the following code

 g :: Int - Float
 g = undefined

 h :: (Foo Int a) = Int - a
 h = g


 I get the error

 Could not deduce (a ~ Float)


 I am not able to understand what has happened here ? The restriction Foo
 Int a should have restricted the type of h to Int - Float as shown in
 the inferred type of f.


 - Satvik

 ___
 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 install fails due to recent HUnit

2012-09-03 Thread Erik Hesselink
On Tue, Aug 28, 2012 at 6:09 PM, Bryan O'Sullivan b...@serpentine.com wrote:
 On Mon, Aug 27, 2012 at 10:52 AM, Bryan O'Sullivan b...@serpentine.com
 wrote:

 The reason you're seeing build breakage is that the .cabal files of the
 broken packages were edited in-place without communicating with any of the
 package authors.

 Not to flog a dead horse, but:

 Just yesterday we had a communication from someone on the Gentoo Linux
 packaging team that their checksum validation for the bloomfilter package
 was failing. This problem arose because of the hand-editing of the package,
 but confusion arose in the bug report due to misattribution of the source of
 the error.

 https://github.com/haskell/cabal/issues/1017

 Hand-editing uploaded tarballs: just don't do it, kids!

Not to flog a dead horse, but:

All our builds broke again yesterday due to this bug. The package was
iteratee-0.8.9.3, though given the vocal opposition of Bryan
O'Sullivan, I won't advocate fixing it in place just now.

I've built the test in the Cabal library to reject packages with
conditionals in the test-suites section. I'm just not sure if we want
to implement this on hackage, and for how long.

I'm not quite sure how old this cabal version is that is causing the
problems, but the haskell platform it comes with is 2011.2, which
means the second quarter of 2011, so that is a little over a year old.
It comes with Ubuntu 11.10, which is less than a year old.

I was going to argue to support versions of cabal (and GHC) for at
least a year. That means that if you're on Ubuntu, which has releases
every 6 months, you have 6 months to upgrade. However, that year has
already expired for cabal 0.10, or is about to expire if you count the
Ubuntu release it came with.

So what do others think? Does the haskell community want to support
anything other than the bleeding edge? If so, for how long?

Regards,

Erik

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


Re: [Haskell-cafe] Build regressions due to GHC 7.6

2012-08-30 Thread Erik Hesselink
On Thu, Aug 30, 2012 at 7:26 AM, Bryan O'Sullivan b...@serpentine.com wrote:
 The FFI now requires constructors to be visible, so CInt has to be
 imported as CInt(..).

I think there was already a warning about this one in GHC 7.4, so
there was more time to fix it. Not to say I don't feel your pain, but
if deprecating/warning and then removing in the next release isn't
good enough, nothing can ever be changed.

Erik

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


Re: [Haskell-cafe] Build regressions due to GHC 7.6

2012-08-30 Thread Erik Hesselink
Note that this does not work if you want to support multiple versions
of GHC, and might not work in general, since

* The hiding of catch is needed for preludes that still have it, since
otherwise it will probably conflict with the one from
Control.Exception.
* Older versions do not have constructors for the FFI types, leading
to warnings (or errors, I'm not sure).
* Packages might not work with the new bytestring version, since the
API has breaking changes (although they're supposed to be minor).

For the first two, you need to add some CPP, for the last, you need
actual testing.

Erik

On Thu, Aug 30, 2012 at 3:03 PM, Alexander Kjeldaas
alexander.kjeld...@gmail.com wrote:
 This is very unfortunate, but this is crucially a tooling issue.  I am going
 to wave my hands, but..

 Ignore the mapreduce in the following video, but look at the use of clang to
 do automatic refactoring of C++.  This is *incredibly* powerful in dealing
 with updates to APIs.

 http://www.llvm.org/devmtg/2011-11/videos/Carruth_ClangMapReduce-desktop.mp4

 But without all that fancy tech, *just* having all of Hackage source code in
 one repository and using perl/regexps, fixing these types of issues is O(1)
 instead of O(n).

 All of the issues you mention seems to be fixable by a few lines of perl *if
 we had the repository*.

 [a few hours later]

 Actually, I went and downloaded all of hackage, put it into a git repository
 and fixed these issues:

 Fix catch
 perl -ni -e 'print unless /import Prelude hiding \(catch\)/' $(git grep
 'import Prelude hiding (catch)')

 Fix CInt constructors (lots of other stuff from Foreign.C.Types not fixed
 though)
 perl -p -i -e 's/^import Foreign.C.Types(.*)CInt([^(])/import
 Foreign.C.Types${1}CInt(..)${1}/g' $(git grep -l '^import.*CInt')

 Fix bytestring versioning
 perl -p -i -e 's/bytestring( +)=([0-9. ]+)([
 ]*)0.10/bytestring$1=$2${3}0.11/g' $(git grep 'bytestring.* *0\.')

 Patch to hackage:
 http://ge.tt/6Cb5ErM/v/0

 I understand that this doesn't help anyone, but if there was a way fix,
 upload, and get *consensus* on a few regexps like this, then doing API
 changes wouldn't be such a headache.

 Alexander

 On 30 August 2012 07:26, Bryan O'Sullivan b...@serpentine.com wrote:

 Since the release of the GHC 7.6 RC, I've been going through my packages
 and fixing up build problems so that people who upgrade to 7.6 will have a
 smooth ride.

 Sad to say, my experience of 7.6 is that it has felt like a particularly
 rough release for backwards incompatibility. I wanted to quantify the pain,
 so I did some research, and here's what I found.

 I maintain 25 open source Haskell packages. Of these, the majority have
 needed updates due to the GHC 7.6 release:

 base16-bytestring
 blaze-textual
 bloomfilter
 configurator
 criterion
 double-conversion
 filemanip
 HDBC-mysql
 mwc-random
 pcap
 pool
 riak-haskell-client
 snappy
 text
 text-format
 text-icu

 That's 16 out of 25 packages I've had to update. I've also either reported
 bugs on, or had to fix, several other people's packages along the way (maybe
 four?). So let's say I've run into problems with 20 out of the combined 29
 packages of mine and my upstreams.

 The reasons for these problems fall into three bins:

 Prelude no longer exports catch, so a lot of import Prelude hiding
 (catch) had to change.
 The FFI now requires constructors to be visible, so CInt has to be
 imported as CInt(..).
 bytestring finally got bumped to 0.10, so many upper bounds had to be
 relaxed (cf my suggestion that the upper-bounds-by-default policy is
 destructive).

 It has been a lot of work to test 29 packages, and then modify, rebuild,
 and release 20 of them. It has consumed most of my limited free time for
 almost two weeks. Worse, this has felt like make-work, of no practical
 benefit to anyone beyond scrambling to restore the status quo ante.

 If over half of my packages needed fixing, I'm alarmed at the thought of
 the effects on the rest of Hackage.

 I'm torn over this. I understand and agree with the impetus to improve the
 platform by tidying things up, and yet just two seemingly innocuous changes
 (catch and FFI) have forced me to do a bunch of running to stand still.

 I don't have any suggestions about what to do; I know that it's hard to
 estimate the downstream effects of what look like small changes. And so I'm
 not exactly complaining. Call this an unhappy data point.

 ___
 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


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


Re: [Haskell-cafe] Build regressions due to GHC 7.6

2012-08-30 Thread Erik Hesselink
On Thu, Aug 30, 2012 at 7:24 PM, wren ng thornton w...@freegeek.org wrote:
 On 8/30/12 10:26 AM, Erik Hesselink wrote:
 * Packages might not work with the new bytestring version, since the
 API has breaking changes (although they're supposed to be minor).

 For the first two, you need to add some CPP, for the last, you need
 actual testing.

 Actually, that can be more problematic than you suspect. In particular,
 hsc2hs does not play nicely with Cabal's MIN_VERSION_foo(1,2,3) macros. So
 if you're using hsc2hs, which is common for certain FFI uses, then you have
 to put up with the warnings or rely on the __GLASGOW_HASKELL__ macro in lieu
 of the MIN_VERSION_foo(1,2,3) macros. It's doable, but it's uglier and more
 hackish than it ought to be.

Ah yes, I found this out a while ago on one of my packages. As a tip
for those doing this: the value of __GLASGOW_HASKELL__ is xyy, with x
the first version component, and y the second. So, say, 7.4.2 has a
value of 704, not 742.

Erik

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


Re: [Haskell-cafe] happstack simpleHTTP state monad

2012-08-30 Thread Erik Hesselink
The way you wrote it, you run the state transformer once for each
request. So the state will be available within a single request, but
not between requests. If you want to persist state between requests,
you can use one the the mutable variables available (TVar or MVar are
good choices; IORefs also work, but you have to take care about
concurrency, using e.g. atomicModifyIORef). Create them before calling
simpleHTTP, then pass them in to use them in your handler. You can put
them in a ReaderT to avoid passing them, if you want.

Another choice is to use something like a database or the file system
for persistent state. Databases usually handle most concurrency
problems for you, while file systems don't.

Regards,

Erik

On Thu, Aug 30, 2012 at 7:29 PM, Corentin Dupont
corentin.dup...@gmail.com wrote:
 Hi all,
 I'm trying to make a web server that manages its own state. The user can
 issue commands that modifies the state.
 I did like below but unfortunatly the state is not keep after a command is
 issued...
 What is the right way to do it? Is there any example sites with an internal
 state with happstack?

 data Game = (the state of my game)
 type NomicServer = ServerPartT (StateT Game IO)

 launchWebServer :: Game - IO ()
 launchWebServer initialState = do
putStrLn Starting web server...\nTo connect, drive your browser to
 \http://localhost:8000/Login\;
d - getDataDir
simpleHTTP' unpackStateT nullConf $ server d


 server :: FilePath - ServerPartT (StateT Game IO) Response
 server d sh = mconcat [fileServe [] d, do
decodeBody (defaultBodyPolicy /tmp/
 4096 4096 4096)
html - implSite http://localhost:8000/;
  nomicSite
return $ toResponse html]

 unpackStateT:: Game - UnWebT (StateT Game IO) Response - UnWebT IO
 Response
 unpackStateT g w = evalStateT w g

 --handler for web routes
 nomicSite :: Site PlayerCommand (NomicServer Html)
 nomicSite = setDefault (Noop 0) Site {
   handleSite = \f url - unRouteT (routedNomicCommands url) f
 , formatPathSegments = \u - (toPathSegments u, [])
 , parsePathSegments  = parseSegments fromPathSegments
 }

 Thanks a lot,
 Corentin
 ___
 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] map over Bijections

2012-08-27 Thread Erik Hesselink
If you remove the second argument (which you don't use), you have the
function `liftBij` that is in fclabels.

Erik

On Mon, Aug 27, 2012 at 3:55 PM, Sergey Mironov ier...@gmail.com wrote:
 Hi. I need map equivalent for Bijection type which is defined in fclabels:

 data Bijection (~) a b = Bij { fw :: a ~ b, bw :: b ~ a }

 instance Category (~) = Category (Bijection (~)) where ...

 I can define this function as follows:
 mapBij :: Bijection (-) a c - Bijection (-) [a] [b] - Bijection (-) [a] 
 [c]
 mapBij b1 b = (map (fw b1)) `Bij` (map (bw b1))

 but do I really need to do it explicitly? Can I obtain same result
 using some Category combinators or other common stuff?

 Sergey

 ___
 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 install fails due to recent HUnit

2012-08-27 Thread Erik Hesselink
On Mon, Jul 30, 2012 at 3:33 PM, Ross Paterson r...@soi.city.ac.uk wrote:
 On Mon, Jul 30, 2012 at 01:46:24PM +0100, Niklas Broberg wrote:
 On Wed, Jul 25, 2012 at 12:22 PM, Ross Paterson r...@soi.city.ac.uk wrote:

 As I understand it, the plan is to modify the following packages in
 hackage in-situ to remove the test sections (which contain the 
 troublesome
 conditionals):

   HUnit-1.2.5.0
   bloomfilter-1.2.6.10
   codemonitor-0.1
   codemonitor-0.2
   fixhs-0.1.4
   leksah-server-0.12.0.3
   leksah-server-0.12.0.4
   leksah-server-0.12.0.5
   pqc-0.5
   pqc-0.5.1

 Does anyone object?

 No objections, but some impatience. ;-)

 OK, done.

I'm seeing this again, on abstract-deque-0.1.6. Ross, can you fix it again?

For the future: is there any way to prevent this from happening?
Perhaps a check in hackage? I'd be willing to implement this if people
think this is a good idea, and I'm pointed in the right direction.

Erik

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


Re: [Haskell-cafe] Cabal install fails due to recent HUnit

2012-08-27 Thread Erik Hesselink
On Mon, Aug 27, 2012 at 7:52 PM, Bryan O'Sullivan b...@serpentine.com wrote:
 On Mon, Aug 27, 2012 at 9:57 AM, Erik Hesselink hessel...@gmail.com wrote:

 I'm seeing this again, on abstract-deque-0.1.6. Ross, can you fix it
 again?


 Hang on a second.

 The reason you're seeing build breakage is that the .cabal files of the
 broken packages were edited in-place without communicating with any of the
 package authors.

 I understand that the collective intentions around this were good, but by
 fixing things without telling anyone, package maintainers have no way to
 know that anything has happened. Now we are seeing the problem begin to
 recur as people issue new releases that don't incorporate those changes.

 So. Let's have a little conversation about how to handle this sustainably
 before wasting more of Ross's time.

Yes, you are right. So the question is how long to support systems
with the old cabal 0.10. This is the one included with the previous
haskell platform (and thus lots of linux distro's), which is less than
a year old. But it's also pretty old, since there weren't any cabal
releases for a while.

The other question is how useful test suites in a released package
are. Aren't they much more useful (and used more often) in source
repositories?

If we do agree that we want to prevent this problem for a while (which
I'm not sure about), we should probably do it by preventing uploads
for packages like this. That way, package maintainers will know what
is going on, just like with the other 'package quality' issues hackage
enforces.

Erik

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


Re: [Haskell-cafe] How to implement instance of MonadBaseControl IO

2012-08-24 Thread Erik Hesselink
I'm not sure if you already have something working, but we have
several in our codebase, all following a similar pattern. For example:

newtype GeoServer a = GeoServer { unGeoServer :: ReaderT
GeoServerState (ServerPartT IO) a }

instance MonadBaseControl IO GeoServer where
  newtype StM GeoServer a = StMGeoServer { unStMGeoServer :: StM
(ReaderT GeoServerState (ServerPartT IO)) a }
  liftBaseWith f = GeoServer (liftBaseWith (\run - f (liftM
StMGeoServer . run . unGeoServer)))
  restoreM = GeoServer . restoreM . unStMGeoServer

Erik

On Wed, Aug 22, 2012 at 9:16 AM, yi huang yi.codepla...@gmail.com wrote:
 I have a `newtype Yun a = Yun { unYun :: ReaderT YunEnv (ResourceT IO) a }`
 , and i need to define an instance of `MonadBaseControl IO` for it.
 Newtype instance deriving don't work here. I guess the answer is simple, i
 just can't figure it out, hope anybody can lightening me.

 Best regards.
 Yihuang.

 ___
 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] Rigid skolem type variable escaping scope

2012-08-22 Thread Erik Hesselink
On Wed, Aug 22, 2012 at 10:13 PM, Matthew Steele mdste...@alum.mit.edu wrote:
 On Aug 22, 2012, at 3:02 PM, Lauri Alanko wrote:

 Quoting Matthew Steele mdste...@alum.mit.edu:

{-# LANGUAGE Rank2Types #-}

class FooClass a where ...

foo :: (forall a. (FooClass a) = a - Int) - Bool
foo fn = ...

newtype IntFn a = IntFn (a - Int)

bar :: (forall a. (FooClass a) = IntFn a) - Bool
bar (IntFn fn) = foo fn

 In case you hadn't yet discovered it, the solution here is to unpack the 
 IntFn a bit later in a context where the required type argument is known:

 bar ifn = foo (case ifn of IntFn fn - fn)

 Hope this helps.

 Ah ha, thank you!  Yes, this solves my problem.

 However, I confess that I am still struggling to understand why unpacking 
 earlier, as I originally tried, is invalid here.  The two implementations are:

 1) bar ifn = case ifn of IntFn fn - foo fn
 2) bar ifn = foo (case ifn of IntFn fn - fn)

 Why is (1) invalid while (2) is valid?  Is is possible to make (1) valid by 
 e.g. adding a type signature somewhere, or is there something fundamentally 
 wrong with it?  (I tried a few things that I thought might work, but had no 
 luck.)

 I can't help feeling like maybe I am missing some small but important piece 
 from my mental model of how rank-2 types work.  (-:  Maybe there's some paper 
 somewhere I need to read?

Look at it this way: the argument ifn has a type that says that *for
any type a you choose* it is an IntFn. But when you have unpacked it
by pattern matching, it only contains a function (a - Int) for *one
specific type a*. At that point, you've chosen your a.

The function foo wants an argument that works for *any* type a. So
passing it the function from IntFn isn't enough, since that only works
for *one specific a*. So you pass it a case expression that produces a
function for *any a*, by unpacking the IntFn only inside.

I hope that makes sense (and is correct...)

Erik

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


Re: [Haskell-cafe] Platform Versioning Policy: upper bounds are not our friends

2012-08-20 Thread Erik Hesselink
I am strongly against this, especially for packages in the platform.

If you fail to specify an upper bound, and I depend on your package,
your dependencies can break my package! For example, say I develop
executable A and I depend on library B == 1.0. Library B depends on
library C = 0.5 (no upper bound). Now C 0.6 is released, which is
incompatible with B. This suddenly breaks my build, even though I have
not changed anything about my code or dependencies. This goes against
the 'robust' aspect mentioned as one of the properties of the Haskell
platform, and against the Haskell philosophy of correctness in
general.

This is not an imaginary problem. At my company, we've run into these
problems numerous times already. Since we also have people who are not
experts at Cabal and the Haskell ecosystem building our software, this
can be very annoying. The fix is also not trivial: we can add a
dependency on a package we don't use to all our executables or we can
fork the library (B, in the example above) and add an upper bound/fix
the code. Both add a lot of complexity that we don't want. Add to that
the build failures and associated emails from CI systems like Jenkins.

I can see the maintenance burder you have, since we have to do the
same for our code. But until some Cabal feature is added to ignore
upper bounds or specify soft upper bounds, please follow the PVP, also
in this regard. It helps us maintain a situation where only our own
actions can break our software.

Erik

On Wed, Aug 15, 2012 at 9:38 PM, Bryan O'Sullivan b...@serpentine.com wrote:
 Hi, folks -

 I'm sure we are all familiar with the phrase cabal dependency hell at this
 point, as the number of projects on Hackage that are intended to hack around
 the problem slowly grows.

 I am currently undergoing a fresh visit to that unhappy realm, as I try to
 rebuild some of my packages to see if they work with the GHC 7.6 release
 candidate.

 A substantial number of the difficulties I am encountering are related to
 packages specifying upper bounds on their dependencies. This is a recurrent
 problem, and its source lies in the recommendations of the PVP itself
 (problematic phrase highlighted in bold):

 When publishing a Cabal package, you should ensure that your dependencies
 in the build-depends field are accurate. This means specifying not only
 lower bounds, but also upper bounds on every dependency.


 I understand that the intention behind requiring tight upper bounds was
 good, but in practice this has worked out terribly, leading to depsolver
 failures that prevent a package from being installed, when everything goes
 smoothly with the upper bounds relaxed. The default response has been for a
 flurry of small updates to packages in which the upper bounds are loosened,
 thus guaranteeing that the problem will recur in a year or less. This is
 neither sensible, fun, nor sustainable.

 In practice, when an author bumps a version of a depended-upon package, the
 changes are almost always either benign, or will lead to compilation failure
 in the depending-upon package. A benign change will obviously have no
 visible effect, while a compilation failure is actually better than a
 depsolver failure, because it's more informative.

 This leaves the nasty-but-in-my-experience-rare case of runtime failures
 caused by semantic changes. In these instances, a downstream package should
 reactively add an upper bound once a problem is discovered.

 I propose that the sense of the recommendation around upper bounds in the
 PVP be reversed: upper bounds should be specified only when there is a known
 problem with a new version of a depended-upon package.

 ___
 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] fclabels 0.5

2012-08-20 Thread Erik Hesselink
Untested, but this should be about right:

osi (Bij f b) = iso (Bij b f)

Erik

On Mon, Aug 20, 2012 at 2:35 PM, Sergey Mironov ier...@gmail.com wrote:
 Hi. I'm porting old code, which uses fclabels 0.5. Old fclabels
 define Iso typeclass as follows:

 class Iso f where
   iso :: a :-: b - f a - f b
   iso (Lens a b) = osi (b - a)
   osi :: a :-: b - f b - f a
   osi (Lens a b) = iso (b - a)

 Newer one defines iso:

 class Iso (~) f where
   iso :: Bijection (~) a b - f a ~ f b

 instance Arrow (~) = Iso (~) (Lens (~) f) where
   iso bi = arr ((\a - lens (fw bi . _get a) (_set a . first (bw bi))) . 
 unLens)

 instance Arrow (~) = Iso (~) (Bijection (~) a) where
   iso = arr . (.)

 but no osi. I'm not a guru in categories, can you help me define osi?

 Thanks
 Sergey.

 ___
 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] Platform Versioning Policy: upper bounds are not our friends

2012-08-20 Thread Erik Hesselink
Hub looks interesting, I'll have to try it out (though I'm not on an
RPM based distro). But isn't this the goal of things like semantic
versioning [0] and the PVP? To know that you can safely upgrade to a
bugfix release, and relavily safely to a minor release, but on a major
release, you have to take care?

Haskell makes it much easier to see if you can use a new major (or
minor) version of a library, since the type checker catches many (but
not all!) problems for you. However, this leads to libraries breaking
their API's much more easily, and that in turn causes the problems
voiced in this thread. However, fixing all versions seems like a bit
of a blunt instrument, as it means I'll have to do a lot of work to
bring even bug fixes in.

Erik

[0] http://semver.org/



On Mon, Aug 20, 2012 at 3:13 PM, Chris Dornan ch...@chrisdornan.com wrote:
 I think we should encourage stable build environments to know precisely
 which package versions they have been using and to keep using them until
 told otherwise. Even when the types and constraints all work out there is a
 risk that upgraded packages will break. Everybody here wants cabal to just
 install the packages without problem, but if you want to insulate yourself
 from package upgrades surely sticking with proven combinations is the way to
 go.

 Chris

 -Original Message-
 From: haskell-cafe-boun...@haskell.org
 [mailto:haskell-cafe-boun...@haskell.org] On Behalf Of Erik Hesselink
 Sent: 20 August 2012 08:33
 To: Bryan O'Sullivan
 Cc: haskell-cafe@haskell.org
 Subject: Re: [Haskell-cafe] Platform Versioning Policy: upper bounds are not
 our friends

 I am strongly against this, especially for packages in the platform.

 If you fail to specify an upper bound, and I depend on your package, your
 dependencies can break my package! For example, say I develop executable A
 and I depend on library B == 1.0. Library B depends on library C = 0.5 (no
 upper bound). Now C 0.6 is released, which is incompatible with B. This
 suddenly breaks my build, even though I have not changed anything about my
 code or dependencies. This goes against the 'robust' aspect mentioned as one
 of the properties of the Haskell platform, and against the Haskell
 philosophy of correctness in general.

 This is not an imaginary problem. At my company, we've run into these
 problems numerous times already. Since we also have people who are not
 experts at Cabal and the Haskell ecosystem building our software, this can
 be very annoying. The fix is also not trivial: we can add a dependency on a
 package we don't use to all our executables or we can fork the library (B,
 in the example above) and add an upper bound/fix the code. Both add a lot of
 complexity that we don't want. Add to that the build failures and associated
 emails from CI systems like Jenkins.

 I can see the maintenance burder you have, since we have to do the same for
 our code. But until some Cabal feature is added to ignore upper bounds or
 specify soft upper bounds, please follow the PVP, also in this regard. It
 helps us maintain a situation where only our own actions can break our
 software.

 Erik

 On Wed, Aug 15, 2012 at 9:38 PM, Bryan O'Sullivan b...@serpentine.com
 wrote:
 Hi, folks -

 I'm sure we are all familiar with the phrase cabal dependency hell
 at this point, as the number of projects on Hackage that are intended
 to hack around the problem slowly grows.

 I am currently undergoing a fresh visit to that unhappy realm, as I
 try to rebuild some of my packages to see if they work with the GHC
 7.6 release candidate.

 A substantial number of the difficulties I am encountering are related
 to packages specifying upper bounds on their dependencies. This is a
 recurrent problem, and its source lies in the recommendations of the
 PVP itself (problematic phrase highlighted in bold):

 When publishing a Cabal package, you should ensure that your
 dependencies in the build-depends field are accurate. This means
 specifying not only lower bounds, but also upper bounds on every
 dependency.


 I understand that the intention behind requiring tight upper bounds
 was good, but in practice this has worked out terribly, leading to
 depsolver failures that prevent a package from being installed, when
 everything goes smoothly with the upper bounds relaxed. The default
 response has been for a flurry of small updates to packages in which
 the upper bounds are loosened, thus guaranteeing that the problem will
 recur in a year or less. This is neither sensible, fun, nor sustainable.

 In practice, when an author bumps a version of a depended-upon
 package, the changes are almost always either benign, or will lead to
 compilation failure in the depending-upon package. A benign change
 will obviously have no visible effect, while a compilation failure is
 actually better than a depsolver failure, because it's more informative.

 This leaves the nasty-but-in-my-experience-rare case of runtime
 failures caused

Re: [Haskell-cafe] Flipping type constructors

2012-08-18 Thread Erik Hesselink
The next version of GHC will have an extension for kind polymorphism.
I'm not sure if it has to be enabled in the module that defines flip
or in the module that uses it, but it might help.

Erik

On Tue, Aug 14, 2012 at 1:38 AM, Tony Morris tonymor...@gmail.com wrote:
 I have a data-type that is similar to EitherT, however, I have ordered
 the type variables like so:

 data EitherT (f :: * - *) (a :: *) (b :: *) = ...

 This allows me to declare some desirable instances:

 instance Functor f = Bifunctor (EitherT f)
 instance Foldable f = Bifoldable (EitherT f)
 instance Traversable f = Bitraversable (EitherT f)

 However, I am unable to declare a MonadTrans instance:

 instance MonadTrans (EitherT a) -- kind error

 I looked at Control.Compose.Flip to resolve this, but it does not appear
 to be kind-polymorphic.
 http://hackage.haskell.org/packages/archive/TypeCompose/0.9.1/doc/html/src/Control-Compose.html#Flip

 I was wondering if there are any well-developed techniques to deal with
 this? Of course, I could just write my own Flip with the appropriate
 kinds and be done with it. Maybe there is a more suitable way?


 --
 Tony Morris
 http://tmorris.net/



 ___
 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] What Haskell Records Need

2012-08-02 Thread Erik Hesselink
Isn't this exactly the problem solved by all the lens packages?
Current popular ones are fclabels [0] and data-lens [1].

[0] http://hackage.haskell.org/package/fclabels
[1] http://hackage.haskell.org/package/data-lens

On Thu, Aug 2, 2012 at 7:34 AM, Jonathan Geddes
geddes.jonat...@gmail.com wrote:
 Greetings,

 tl;dr - What Haskell Records need are
 semantic editor combinators for free.

 I know this is yet another Record proposal
 among many, but none of them out there
 strike me as being exactly what I want in
 Haskell.

 Take the following types from a contrived
 example.

type Salary = Integer

data Job = Job
  { title  :: String
  , salary :: Salary
  }

data Person = Person
  { name :: String
  , job  :: Job
  }

 Since I've used record syntax, I get
 getter/accessor functions (title, salary,
 name, job) for free. Now suppose I want to
 create an aggregate getter function: return
 the salary of a given person. Piece of cake,
 it's just function composition

getSalary :: Person - Salary
getSalary = salary . job

 Done! Now suppose I want to write a
 setter/mutator function for the same nested
 field

setSalaryMessy :: Salary - Person - Person
setSalaryMessy newSalary person =
  person {
job = (job person) {
  salary = newSalary
}
  }

 Ouch! And that's not even very deeply nested.
 Imagine 4 or 5 levels deep. It really makes
 Haskell feel clunky next to `a.b.c.d = val`
 that you see in other languages. Of course
 immutability means that the semantics of
 Haskell are quite different (we're creating
 new values here, not updating old ones) but
 it's still common to model change using these
 kinds of updates.

 What if along with the free getters that
 the compiler generates when we use record
 syntax, we also got semantic editor
 combinator (SEC) functions[0] that could be
 used as follows?

setSalary newSalary = job' $ salary' (const newSalary)

giveRaise amount = job' $ salary' (+amount)

givePercentRaise percent = job' $ salary' (*(1+percent))

 For each field x, the compiler generates a
 function x' (the tic is mnemonic for change).
 These little functions aren't hard to write,
 but they're classic boilerplate.

job' :: (Job - Job) - Person - Person
job' f person = person {job = f $ job person}

salary' :: (Salary - Salary) - Job - Job
salary' f job = job { salary = f $ salary job}

 These type of utility functions are a dream
 when working with any reference type or
 State Monad.

 modify $ givePercentRaise 0.25

 The compiler could also generate polymorphic
 SEC functions for polymorphic fields.
 Further, the compiler could disallow using
 old-style update syntax for fields whose SEC
 update function is not in scope, giving us
 fine-grained control over access and update.
 On the other hand we currently have to create
 new functions to achieve this (exporting the
 getter means exporting the ability to update
 as well, currently).

 Of course this doesn't address the
 namespacing issues with records, but it is
 likely nicely orthogonal to other proposals
 which do.

 Also note that there's a package on hackage [1]
 that will generate SEC functions using TH.
 It's nice, but I prefer the style of field
 names used above for updaters (field' vs
 editField).

 Let me know what you think. I'll write up an
 official proposal if there's a bit of
 general interest around this.

 Thanks for reading,

 --Jonathan

 [0] - http://conal.net/blog/posts/semantic-editor-combinators
 [1] -
 http://hackage.haskell.org/packages/archive/sec/0.0.1/doc/html/Data-SemanticEditors.html




 ___
 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] What Haskell Records Need

2012-08-02 Thread Erik Hesselink
On Thu, Aug 2, 2012 at 12:30 PM, Andrew Butterfield
andrew.butterfi...@scss.tcd.ie wrote:

 On 2 Aug 2012, at 09:25, Erik Hesselink wrote:

 Isn't this exactly the problem solved by all the lens packages?
 Current popular ones are fclabels [0] and data-lens [1].

 [0] http://hackage.haskell.org/package/fclabels
 [1] http://hackage.haskell.org/package/data-lens

 Not sure what all of these do, but I have a simple solution I use
 in my work:

They do exactly that. They create 'lenses' which are
getters/setters/modifiers combined, and allow you to compose these to
get/set/modify deep inside nested data types. Look at the examples in
the fclabels documentation [2] for more details.

[2] 
http://hackage.haskell.org/packages/archive/fclabels/1.1.4/doc/html/Data-Label.html

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


Re: [Haskell-cafe] GHC rendering of non-ASCII characters configurable?

2012-08-01 Thread Erik Hesselink
On Wed, Aug 1, 2012 at 2:35 AM, Richard Cobbe co...@ccs.neu.edu wrote:
 Well, I initially went with String because I didn't want to clutter up my
 code with all of the calls to 'pack', especially around string literals.
 I'm open to being convinced that it's worth it to switch, though.

For string literals, you can turn on OverloadedStrings to get rid of
the calls to 'pack'.

Erik

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


Re: [Haskell-cafe] Cabal install fails due to recent HUnit

2012-07-23 Thread Erik Hesselink
On Monday, July 23, 2012, Simon Hengel wrote:


 On Mon, Jul 23, 2012 at 12:51:32PM -0500, Stephen Paul Weber wrote:
   Currently you would have to do the upgrade manually, as `cabal-install
   cabal-install` won't work (or alternatively edit your local
   ~/.cabl/packages/hackage.haskell.org/00-index.tar).
 
  Pending a fix on hackage (hopefully) I've been using `cabal copy  cabal
  register` to grab specific packages today.
 
  How would I go about fixing my 00-index.tar?  I tride de-tarring,
 deleting
  the recent versions of HUnit, and re-tarring, and when I copy that file
 in
  cabal starts telling me no packages exist...?

 E.g. with vim, you can edit files in the tar file (in-place).  That is
 what I did, and it worked fine.


I use

  tar f 00-index.tar --delete Hunit/1.2.5.0/Hunit.cabal

Works with GNU tar, not with BSD/mac.

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


Re: [Haskell-cafe] Fwd: hackage compile failure with QuickCheck 2.5

2012-07-18 Thread Erik Hesselink
On Wed, Jul 18, 2012 at 10:19 AM, Ross Paterson r...@soi.city.ac.uk wrote:
 On Wed, Jul 18, 2012 at 06:50:31AM +0100, Andres Löh wrote:
 Using --avoid-reinstalls blindly or as a default flag is also
 unfortunately not a good idea in general. There are simply too many
 cases where installing older versions of packages (which is often the
 only thing that helps) is not really the solution you want. That's
 also the reason why it's not enabled by default.

 I need a combination of flags that I can use blindly with the greatest
 chance of success.  The default doesn't work on packages like this one:

 % cabal --version
 cabal-install version 0.14.0
 using version 1.14.0 of the Cabal library
 % cabal install sbv-2.2
 Resolving dependencies...
 In order, the following would be installed:
 HUnit-1.2.4.3 (new package)
 containers-0.5.0.0 (new version)
 random-1.0.1.1 (new package)
 strict-concurrency-0.2.4.1 (new package)
 syb-0.3.7 (new package)
 template-haskell-2.7.0.0 (reinstall) changes: containers-0.4.2.1 - 0.5.0.0
 QuickCheck-2.5 (new package)
 transformers-0.3.0.0 (new package)
 mtl-2.1.2 (new package)
 sbv-2.2 (new package)
 cabal: The following packages are likely to be broken by the reinstalls:
 ghc-7.4.1
 Use --force-reinstalls if you want to install anyway.

I don't think you can install this package on 7.4. As Andres said, it
requires containers 0.5, but ghc 7.4's base libraries (in this case,
template-haskell) use containers 0.4, and can't be reinstalled. I
guess your best bet is to use sbv-2.1, which depends on containers =
0.3, or to unpack it and see if you can loosen the containers
dependency and see if it still works with 0.4

So in short, no combination of flags will work in this case, I think.
Failure is the best option.

Erik

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


Re: [Haskell-cafe] Fwd: hackage compile failure with QuickCheck 2.5

2012-07-18 Thread Erik Hesselink
On Wed, Jul 18, 2012 at 11:29 AM, Ross Paterson r...@soi.city.ac.uk wrote:
 On Wed, Jul 18, 2012 at 09:35:52AM +0100, Erik Hesselink wrote:
 I don't think you can install this package on 7.4. As Andres said, it
 requires containers 0.5, but ghc 7.4's base libraries (in this case,
 template-haskell) use containers 0.4, and can't be reinstalled. I
 guess your best bet is to use sbv-2.1, which depends on containers =
 0.3, or to unpack it and see if you can loosen the containers
 dependency and see if it still works with 0.4

 I'm talking about unattended automated builds, so tweaking isn't an
 option.  On the other hand breaking the package environment isn't so bad,
 because I'm throwing it away after each build.

We use --force-reinstalls for automated builds as well, inside a
cabal-dev sandbox. I think that flag is a fine default for such
situations.

 So in short, no combination of flags will work in this case, I think.
 Failure is the best option.

 Actually --force-reinstalls does work in this case, and this thread began
 with Levent being unhappy with the failure option for his package, so
 I'm tempted to use that flag on all hackage builds.

Does that mean that you *can* reinstall template-haskell? I didn't know that...

Erik

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


[Haskell-cafe] Cabal install fails due to recent HUnit

2012-07-18 Thread Erik Hesselink
Hi all,

All cabal installs using cabal-install-0.10.2 are currently failing
for us. This is due to the cabal file for HUnit-1.2.5.0, which was
recently uploaded to hackage. The ouput I'm getting from cabal is
just:

Reading available packages...
Resolving dependencies...
cabal: Couldn't read cabal file HUnit/1.2.5.0/HUnit.cabal

If I unpack HUnit-1.2.5.0 and call 'cabal configure', I get:

cabal: HUnit.cabal:57: The 'type' field is required for test suites. The
available test types are: exitcode-stdio-1.0

The relevant lines from the cabal file are:

Test-Suite hunit-tests-optimize-0
Type:   exitcode-stdio-1.0

These look fine to me.

Does anyone have any idea how to go about fixing this (on hackage at
least)? Could this package temporarily be removed, to avoid breaking
everyone's cabal?

Erik

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


Re: [Haskell-cafe] Cabal install fails due to recent HUnit

2012-07-18 Thread Erik Hesselink
Hi Martijn,

Yes, upgrading will obviously fix things (we do use 0.14 on our
development machines), but we have not set up any infrastructure for
building a custom cabal on production servers. We just use the one
from the Ubuntu repositories, which uses Cabal 1.10.1.0 on oneiric. So
until we upgrade to precise I guess we have a problem.

Erik

On Wed, Jul 18, 2012 at 5:24 PM, Martijn Schrage mart...@oblomov.com wrote:
 Hi Erik,

 A similar thing happened to me with the GraphViz package. As Duncan
 explained to me, the problem is that Cabal-1.10.0.0 (and I believe also
 1.10.1.0) incorrectly reports an error when conditionals are used in test
 suites.

 Upgrading to Cabal-1.10.2.0 (or cabal-install-0.14.0 with Cabal-1.14.0)
 should fix the problem. Unfortunately, this means your build will not work
 on a fresh Haskell Platform v2012.2.0.0, until HUnit is patched in the
 hackage index.

 Cheers,
 Martijn Schrage -- Oblomov Systems (http://www.oblomov.com)



 On 18-07-12 16:26, Erik Hesselink wrote:

 Hi all,

 All cabal installs using cabal-install-0.10.2 are currently failing
 for us. This is due to the cabal file for HUnit-1.2.5.0, which was
 recently uploaded to hackage. The ouput I'm getting from cabal is
 just:

 Reading available packages...
 Resolving dependencies...
 cabal: Couldn't read cabal file HUnit/1.2.5.0/HUnit.cabal

 If I unpack HUnit-1.2.5.0 and call 'cabal configure', I get:

 cabal: HUnit.cabal:57: The 'type' field is required for test suites. The
 available test types are: exitcode-stdio-1.0

 The relevant lines from the cabal file are:

 Test-Suite hunit-tests-optimize-0
  Type:   exitcode-stdio-1.0

 These look fine to me.

 Does anyone have any idea how to go about fixing this (on hackage at
 least)? Could this package temporarily be removed, to avoid breaking
 everyone's cabal?

 Erik

 ___
 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] Solutions for multi-platform compilation?

2012-07-12 Thread Erik Hesselink
We use Jenkins to build our applications. You can have Jenkins slaves
for different platforms. We also use cabal-dev to sandbox the builds,
separating the environments for different executables. This solution
does require one server for every OS you develop for, but I guess you
need that anyway, for testing.

Erik

On Thu, Jul 12, 2012 at 11:43 AM, Ivan Perez
ivanperezdoming...@gmail.com wrote:
 Hi,
  I work developing multi-platform applications in Haskell. This poses
 the following problem: I cannot compile binaries for windows from
 linux (AFAIK). I solved this problem with the following
 sledgehammer:  I installed windows in a VM, I installed GHC, I
 installed all the C/C++ headers  binaries of the libraries that I use
 (Gtk, OpenGL, SDL, OpenCV, etc.) their Haskell counterparts, and I
 created several scripts that connect to the VM using SSH, push the
 changes to the repo, cabal clean  cabal install all my packages in
 sequence without me having to even login into the windows machine. I
 did this because I was unable to get GHC to run properly in Wine at
 that time (over 2 years ago).

  This solution is still unsatisfactory because:
  1) It's slow, even though Windows itself works fine (well, as well as
 windows can work, but it runs at a decent spped, I can play games and
 all).
  2) When I update a library with lots of dependencies, or GHC itself,
 I have to rebuild almost everything. This is particularly painful with
 big packages like Gtk, for instance. Because I have to tell cabal
 where headers and libraries are located, updating a package is almost
 never an automatic process. I haven't always been able to make GHC
 just pick them up properly with pkg-config.
  3) When I make a change in a library with lots of dependencies,
 recompiling all the packages can take several hours.

 I don't think it's a problem with my machine: I'm giving a fair amount
 of resources to windows, and I use a 3Ghz quadcore with 8GB of RAM.



 Another relevant fact is: I use this for commercial purposes. I have
 customers, each requiring a completely different program, they do not
 have infinite budgets and, if there's a problem in the compilation
 process and something requires my attention and manual intervention
 too often, my salary per hour can easily drop to a ridiculous amount.
 If I'm going to redo this, I'd rather just redo it once.

 Any suggestions? How do you solve this kind of problem in your work 
 environment?

 Cheers,
 Ivan

 ___
 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] how to check thunk

2012-07-02 Thread Erik Hesselink
There is also the 'isevaluated' package (which depends on vacuum, but
seems to do something more involved than your code).

Erik

On Mon, Jul 2, 2012 at 7:40 AM, Chaddaï Fouché chaddai.fou...@gmail.com wrote:
 On Mon, Jul 2, 2012 at 5:29 AM, Kazu Yamamoto k...@iij.ad.jp wrote:
 Hello,

 Are there any ways to see if a value is a thunk or memorized?
 I would like to have a function like:
   isThunk :: a - IO Bool


 vacuum allow that and much more though I don't know if it still works
 correctly on GHC 7.4. Anyway your isThunk is

 isThunk a = fmap GHC.Vacuum.ClosureType.isThunk GHC.Vacuum.closureType

 (Feel free to arrange your imports to make that a bit more readable ;)

 http://hackage.haskell.org/package/vacuum
 --
 Jedaï

 ___
 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] Using promoted lists

2012-06-08 Thread Erik Hesselink
Hi Yves,

The type level numbers have kind Nat, not Int (and so also can't be
negative). They have to be imported from GHC.TypeLits (I'm not sure if
this will change). So the following code works for me in HEAD:

{-# LANGUAGE TypeFamilies, DataKinds #-}

import GHC.TypeLits

type family Something a :: Nat
type instance Something String = 42

Regards,

Erik

On Fri, Jun 8, 2012 at 8:45 AM, Yves Parès yves.pa...@gmail.com wrote:
 Thanks for your answers, Anthony and Erik.

 I'll try with fundeps. I know about HList, but back at the time when I
 looked at it I found quite complex.

 Anthony, the link you gave me [1] tends to show that actually Bool type is
 promoted.

 type family Member x (l :: [*]) :: Bool
 type instance Member x (x ': xs) = True
 works.
 So if I understand well, unlike what I thought when I saw the compilation
 fail, the two x's type variables are actually unified, but then the second
 instance
 type instance Member x (y ': xs) = True
 encompasses the first, so GHC refuses to handle it (as it would at the value
 level with regular case expressions).
 So yes, [1] is exactly what I was trying to do.

 Out of curiosity, I tried with Int, and it works too, I can express:
 type family Something a :: Int
 But then, the following doesn't compile
 type instance Something String = 42
 ( The wild guess '42 does not either ) So I guess we don't have type-level
 integers for now. How are promoted Ints usable then?


 [1] http://hackage.haskell.org/trac/ghc/wiki/NewAxioms



 2012/6/8 AntC anthony_clay...@clear.net.nz

 Yves Parès yves.pares at gmail.com writes:

 
  The doc page
  http://www.haskell.org/ghc/docs/7.4.1/html/users_guide/kind-
 polymorphism-and-promotion.html#promotion show that lists are now usable
 as
 types.So I'm trying to make a type level function to test if a type list
 contains a type. Unless I'm wrong, that calls to the use of a type family.

 {-# LANGUAGE DataKinds, TypeOperators, KindSignatures, TypeFamilies #-}
 data HBool = HTrue | HFalse
   -- Mandatory as Bool type is not currently promoted to a kind

 type family Member x (l :: [*]) :: HBool

 type instance Member x (x ': xs) = HTrue
 type instance Member x (y ': xs) = Member x xs
 type instance Member x (y ': '[]) = HFalse

 But the compiler complains about my instance conflicting.

 Hi Yves, always when you're asking a question like this, give the error
 message in full -- usually it will explain what's wrong.

 In this case I can guess: you have overlapping instances (the first
 overlaps
 the second, the third overlaps the second), which are not allowed for type
 functions (currently -- unless the equations are confluent).

 There's some early work on introducing overlaps to type functions (in a
 controlled way). http://hackage.haskell.org/trac/ghc/wiki/NewAxioms

 And as it happens, several threads are going on in the lists re options
 and
 implications.

  Is what I'm trying to do feasible?

 Promoted lists are really just the same as HLists, but using the standard
 Haskell syntax.

 A membership test is feasible with FunDeps (because they do allow
 overlaps),
 but I guess you know the HList stuff, judging from your HBool. It's
 feasible
 using type equality constraints to achieve the same as HList (so ~ is
 equivalent to HList's TypeCast), also with overlaps.


 Second question: how can type level tuples (also mentioned in the doc
  page)
 be exploited? Aren't they redundant with type-level lists?

 Type-level tuples are fixed length, and provide a flat structure (any
 element
 is equally accessible), whereas lists are expandable, with a nested
 structure
 that means you have to scan down the structure to get to the element you
 want.

 AntC


 ___
 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


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


Re: [Haskell-cafe] ByteString.getContents fails for files 2GB on OS X

2012-06-08 Thread Erik Hesselink
Do you have a 32bit or 64bit GHC build? That might have something to
do with it, if you're nearing 2^32 (or 2^31) bytes.

Erik

On Fri, Jun 8, 2012 at 2:25 AM, Shaun Jackman sjack...@gmail.com wrote:
 Hi,

 Data.ByteString.Char8.getContents fails for files 2GB on OS X. Is
 there a fix for this?

 $ cat getContents.hs
 main = getContents
 $ ./getContents smallFile
 $ ./getContents bigFile
 getContents: stdin: hGetBuf: invalid argument (Invalid argument)
 $ ghc --version
 The Glorious Glasgow Haskell Compilation System, version 7.4.1

 Mac OS X 10.7.4 64-bit

 As a workaround, I used ByteString.Lazy instead of the strict
 ByteString, which worked, but found it was ~4 times slower for my
 program, so I'd like to get the strict ByteString working with large
 files.

 Cheers,
 Shaun

 ___
 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] Using promoted lists

2012-06-07 Thread Erik Hesselink
If you want to get rid of the overlap in your type families, you have
to add an extra argument indicating if the two types are equal. For
this, you need a type family to indicate equality of types. Sadly, the
naive implementation (TEQ x x = True, TEQ x y = False) overlaps and
isn't allowed. I'm not sure how to work around this, I guess you do
need FunDeps, and then you are pulled into HList land. See also my
attempt at extensible records [1].

Regards,

Erik

[1] https://gist.github.com/2492939

On Thu, Jun 7, 2012 at 9:52 PM, Yves Parès yves.pa...@gmail.com wrote:
 The doc page
 http://www.haskell.org/ghc/docs/7.4.1/html/users_guide/kind-polymorphism-and-promotion.html#promotion
 show that lists are now usable as types.

 So I'm trying to make a type level function to test if a type list contains
 a type. Unless I'm wrong, that calls to the use of a type family.

 {-# LANGUAGE DataKinds, TypeOperators, KindSignatures, TypeFamilies #-}

 data HBool = HTrue | HFalse  -- Mandatory as Bool type is not currently
 promoted to a kind

 type family Member x (l :: [*]) :: HBool

 type instance Member x (x ': xs) = HTrue
 type instance Member x (y ': xs) = Member x xs
 type instance Member x (y ': '[]) = HFalse


 But the compiler complains about my instance conflicting. Is what I'm trying
 to do feasible?

 Second question: how can type level tuples (also mentioned in the doc page)
 be exploited? Aren't they redundant with type-level lists?

 ___
 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] Embed Haskell

2012-04-22 Thread Erik Hesselink
Hi Rosario,

lhs2tex [1] has the '\eval' command. See section 12 of the manual.

Erik

[1] http://www.andres-loeh.de/lhs2tex/

On Sun, Apr 22, 2012 at 17:59, Rosario Borda rosario.bo...@sinervis.com wrote:
 Hi All,

 Is there a simple method for embed haskell in other languages, like latex?

 An example in quasiquotation notation:

 \documentclass{article}
 \title{Hello World}
 \begin{document}
   \maketitle
   Hello world! and reversed: [haskell: putStrLn reverse Hello, World!]
 \end{document}

 Many thanks, :)
 Rosario

 ___
 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] strange GHCi type inference behavior involving map and partially applied functions

2012-04-15 Thread Erik Hesselink
GHCi is defaulting the 'a' in 'Show a' to unit because of the extended
defaulting feature [1] in GHCi. If you turn on
NoMonomorphismRestriction in GHCi, you get the same behavior as in
GHC. If you turn on ExtendedDefaulting in GHC, you get the same
behavior as in GHCi.

Erik

[1] 
http://www.haskell.org/ghc/docs/latest/html/users_guide/interactive-evaluation.html#extended-default-rules

On Sun, Apr 15, 2012 at 22:31, Ting Lei tin...@hotmail.com wrote:
 Hi All,

 I found a really strange case where GHC and GHCi behave differently in
 inferring types. It took me hours to figure this out.

 The following program

 {-# LANGUAGE NoMonomorphismRestriction #-}
 g x i = x ++ show i
 [a,b] = map g [X,Y]

 will not load without NoMonomorphismRestriction. With that option, it
 will load and return the correct types (as expected):
 *Main :t [a,b]
 [a,b] :: Show a = [a - [Char]]

 *Main a 1
 X1

 However, if I do the same thing GHCi, the type inferencing seems to have
 been messed up:

 *Main let g x i = x ++ show i
 *Main let [a,b] = map g [X,Y]
 *Main :t [a,b]
 [a,b] :: [() - [Char]]
 *Main :t map g [X,Y]
 map g [X,Y] :: Show a = [a - [Char]]

 Note how in the last two instances the terms on the left and right-hand
 sides of the definition return different types. Also, the correct return
 type should be a list of unary functions taking an (Show a) as
 the parameter. Now the result is unusable:

 *Main a 1
 interactive:52:3:
     No instance for (Num ())
   arising from the literal `1'
     Possible fix: add an instance declaration for (Num ())
     In the first argument of `a', namely `1'
     In the expression: a 1
     In an equation for `it': it = a 1

 I am using GHCi 7.4.1 under windows. I also tried this under GHC 7.0x
 Is this a GHCi bug or could anyone please explain why this can of strange
 behavior happens?
 If this is a bug, could anyone with an account help file a bug for this?

 Thanks in advance,

 Ting


 ___
 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] Generalizing (++) for monoids instead of using ()

2012-04-02 Thread Erik Hesselink
See the relevant trac ticket [1] and the linked mailing list thread.

Erik

[1] http://hackage.haskell.org/trac/ghc/ticket/3339

On Sun, Apr 1, 2012 at 22:58, aditya bhargava bluemangrou...@gmail.com wrote:
 After asking this question:
 http://stackoverflow.com/questions/9963050/standard-way-of-joining-two-data-texts-without-mappend

 I found out that the new infix operator for `mappend` is (). I'm wondering
 why ghc 7.4 didn't generalize (++) to work on monoids instead. To me, (++)
 is much more clear. () means not equal to for me. Can anyone shed light
 on this decision?


 Adit

 --
 adit.io

 ___
 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] Is there a generic way to detect mzero?

2012-03-26 Thread Erik Hesselink
On Mon, Mar 26, 2012 at 21:24, Antoine Latter aslat...@gmail.com wrote:
 On Mon, Mar 26, 2012 at 1:33 PM, Ting Lei tin...@hotmail.com wrote:
 Hi,

 I was writing a code trying to use MonadPlus to detect some error cases
 (representing missing values etc. in pure code). With the Maybe monad, I can
 do this:

 can0 :: (a - Maybe b) - a - Bool
 can0 f x = case f x of
   Nothing - False
   Just  x - True

 And I got the expected result:

 *Main can0 (\x - Just x) 1
 True

 But, when I try to generalize this using MonadPlus, as follows:

 can :: (MonadPlus m) = (a - m b) - a - Bool
 can f x = case f x of
     mzero - False
     _ - True


 I got a warning:

 __testError.hs:31:11:
     Warning: Pattern match(es) are overlapped
  In a case alternative: _ - ...
 Ok, modules loaded: Main.


 Well, you can sort of do it with only MonadPlus - but it really
 depends on your choice of Monad whether or not it does anything like
 what you want:

 can :: (MonadPlus m) = (a - m ()) - a - m Bool
 can f x = (f x  return True) | return false

 For 'Maybe' this works great, but for something like 'List' I couldn't
 even tell you what it would do without reasoning through it.

 So you might be better off with the suggestion from Tobias using Eq

Well, if you accept the following MonadPlus laws:

mzero = f   ==   mzero
mzero `mplus` m   ==   m

Then you can say that for a well-behaving MonadPlus, mzero will return
(only) False in that function. However, I don't think it's guaranteed
that a non-mzero value will give (only) True. In fact, the list monad
will always return the final False.

Erik

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


Re: [Haskell-cafe] ANN: Haskell Platform Versions Comparison Chart

2012-03-18 Thread Erik Hesselink
On Sun, Mar 18, 2012 at 20:28, Simon Hengel s...@typeful.net wrote:
 **  Not really suer about Mac OS X, but I think it requires Xcode, can
    someone confirm this.

Yes, the platform on Mac OS X requires Xcode, which includes gcc.

Erik

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


Re: [Haskell-cafe] Is there a better way to subtyping?

2012-03-14 Thread Erik Hesselink
However, be aware that aFields, bFields and cFields are now partial
functions that will crash when applied to the wrong constructor. Not
a-okay in my book.

Erik

On Wed, Mar 14, 2012 at 02:24, John Meacham j...@repetae.net wrote:
 Why not

 data Super
        = SuperA {
                commonFields :: ()
                aFields :: ()
                }
        | SuperB {
                commonFields :: ()
                bFields :: ()
                }
        | SuperC {
                commonFields :: ()
                cFields :: ()
                }

 reusing the common field names between constructors like this is a-okay.

   John

 ___
 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] Failing to find a function

2012-02-19 Thread Erik Hesselink
Not a single name, but I believe

  liftA2 mplus

is the same function, and much shorter (and more general). It uses the
Applicative instance for (a -). Of course, it also works with liftM2.

Erik

On Sun, Feb 19, 2012 at 12:50, Jon Fairbairn jon.fairba...@cl.cam.ac.uk wrote:

 This is probably a failure of my search fu or some other mental
 lacuna, but is there already a definition of this function
 somewhere:

 \a b - runKleisli $ (Kleisli a) + Kleisli b
 ?

 Hoogling for its type

   MonadPlus m = (a - m b) - (a - m b) - a - m b

 doesn’t net me anything useful.

 --
 Jón Fairbairn                                 jon.fairba...@cl.cam.ac.uk



 ___
 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] Concurrency strategy for 2 threads and rare events

2012-02-08 Thread Erik Hesselink
You could use throwTo to raise an exception in the thread you want to
stop. Otherwise, having some variable (IORef, TVar, MVar) that the
long running thread occasionally checks seems like a good solution.

Erik

On Wed, Feb 8, 2012 at 17:04, JP Moresmau jpmores...@gmail.com wrote:
 Hello, I'm wondering what's the best strategy to use in the following 
 scenario:
 - 2 threads
  - One perform some work that will take time, possibly go on forever
  - Another waits for user input (like commands from the keyboard)
 that affects thread 1 (causing it to stop, in the simplest case)

 I've read a bit on MVar and channels, but they seem to be a lot for
 cases where the reading thread block for input. In my case, I expect
 to have something that thread 2 updates when an event occur, and
 thread 1 checks it regularly. So thread 1 should not block, but should
 check is there something and there is, act on it, otherwise continue
 doing what it was currently doing. I suppose I could just tryTakeMVar
 on a MVar, but is there something more adapted to my needs?

 Thanks!

 --
 JP Moresmau
 http://jpmoresmau.blogspot.com/

 ___
 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-1.10.1.0 and bytestring-0.9.2.1 hackage problem.

2012-02-03 Thread Erik Hesselink
 Same workaround as last time works

 I.e:

  tar -f ~/.cabal/packages/hackage.haskell.org/00-index.tar --delete 
 bytestring/0.9.2.1

This will only work until the next 'cabal update', right? Does anyone
have a better workaround?

 This is the cabal-install shipped with Ubuntu 12.04 (i.e. the unreleased
 beta, which will become the new LTS in April), so buggy or not, it ought
 not to be broken if we can avoid it.  I've filed a bug:

It's also the cabal-install shipped with Ubuntu 11.10, i.e. the
current version that everyone uses. So it would be nice if the
offending version could also be removed from hackage or something
similar to prevent this problem for everyone.

Erik

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


Re: [Haskell-cafe] zlib 0.5.3.2 broken?

2012-02-01 Thread Erik Hesselink
I recently ran into this as well. I found this stack overflow question
[1], where Daniel Fischer notes that a proper solution has been found,
and it shouldn't be long until it reaches hackage. That was one and a
half weeks ago.

Erik

[1] http://stackoverflow.com/questions/8961413/zlib-build-error-with-ghc

On Thu, Feb 2, 2012 at 06:59, Michael Snoyman mich...@snoyman.com wrote:
 Hi all,

 I've received a number of reports of a broken zlib 0.5.3.2 (and
 experienced it myself). Is this a generally known issue?

 As a temporary workaround, I've released a new version of
 zlib-bindings that has an upper bound on zlib to avoid 0.5.3.2 (and
 later). Once a new patched version is released, I'll release an
 updated version of zlib-bindings to remove that overly restrictive
 upper bound.

 Michael

 ___
 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] Data newtype differences. Today: strictness

2012-01-24 Thread Erik Hesselink
An interesting use case for this is that while

  data Void = Void Void

has infinitely many values (undefined, Void undefined, Void (Void
undefined) etc), the newtype version

  newtype Void = Void Void

has only one, bottom. This is a way to define the empty datatype
without extensions.

Erik

On Tue, Jan 24, 2012 at 11:25, Ketil Malde ke...@malde.org wrote:
 Yves Parès yves.pa...@gmail.com writes:

 I had for long thought that data and newtype were equivalent, but then I
 spotted some differences when it comes to strictness.

 data Test = Test Int
 newtype TestN = TestN Int

 Interesting.  I'd thought that

  data Test = Test !Int

 and

  newtype Test = Test Int

 would be equivalent, but here you (well, I had to add the ! myself) show
 a situation where they're not.

 I guess

  pm (Test _) = 12

 is the same as

  pm = \x - case x of Test _ - 12

 which perhaps makes it clearer why it breaks on undefined...

 -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 mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Spurious pattern match warnings with GADTs

2012-01-12 Thread Erik Hesselink
Type classes are open, so nothing prevents someone from adding an
instance 'C0 T1' and calling 't' with constructor 'B', causing a crash
due to the missing pattern.

Erik

On Thu, Jan 12, 2012 at 21:40, Tom Hawkins tomahawk...@gmail.com wrote:
 Let's say I have:

 data T0
 data T1

 data T a where
  A :: T T0
  B :: T T1

 Then I can write the following without getting any non-exhaustive
 pattern match warnings:

 t :: T T0 - String
 t a = case a of
  A - A

 However, if I use type classes to constrain the constructors, instead
 of using the phantom types directly:

 class C0 a
 instance C0 T0

 class C1 a
 instance C1 T1

 data T a where
  A :: C0 a = T a
  B :: C1 a = T a

 Then I get a non-exhaustive pattern match warning on 't'.  How come?
 (I'm using GHC 7.0.4)

 It appears that the intelligent pattern analysis of the first example
 is a relatively recent addition [1].

 -Tom

 [1] http://hackage.haskell.org/trac/ghc/ticket/3476

 ___
 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] If you'd design a Haskell-like language, what would you do different?

2011-12-22 Thread Erik Hesselink
 I would have compose (probably not called '.') read the same way we read
this sentence (and unix pipes) ie left to right.

You can use  from Control.Arrow for that if you want.

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


Re: [Haskell-cafe] ANNOUNCE: partial-lens 0.0.1

2011-12-21 Thread Erik Hesselink
How does this relate to the Maybe lenses in fclabels [1]?

Erik

[1] 
http://hackage.haskell.org/packages/archive/fclabels/1.0.4/doc/html/Data-Label-Maybe.html

On Wed, Dec 21, 2011 at 04:54,  rocon...@theorem.ca wrote:
 Do you miss null references from your old imperative programming days? Wish
 that the worlds best imperative language had null references?  Now your
 wishes have come true with the new partial-lens package!

 partial-lens augment edwardk's data-lens package with partial lens. Partial
 lenses are like regular lenses but have the possibility of not referencing
 anything.  In other words, null references are possible.  One notable
 different with null references from this package is that you can set them
 without getting a run-time error.  Instead setting a null reference is a
 no-op; however it is possible to determine if setting failed from the return
 value of the assignment operation.

 Actually I don't have any applications for partial lenses myself, so if you
 find this library useful, please let me know.  I wrote this mostly because
 we know what partial lenses are in theory (they are the coalgebras of the
 (Identity :+: Store b) comonad) but I wanted to see what a real library
 would look like.

 --
 Russell O'Connor                                      http://r6.ca/
 ``All talk about `theft,''' the general counsel of the American Graphophone
 Company wrote, ``is the merest claptrap, for there exists no property in
 ideas musical, literary or artistic, except as defined by statute.''

 ___
 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] Alternative versus Monoid

2011-12-21 Thread Erik Hesselink
On Wed, Dec 21, 2011 at 14:10, Bas van Dijk v.dijk@gmail.com wrote:
 On 16 December 2011 16:26, Yves Parès limestr...@gmail.com wrote:
 1) What about the First type? Do we {-# DEPRECATE #-} it?

 Personnaly, I'm in favor of following the same logic than Int:
 Int itself is not a monoid. You have to be specific: it's either Sum or
 Mult.

 It should be the same for Maybe: we remove its instance of Monoid, and we
 only use First and Last.

 The reason you need to be specific with Int is that it's not clear
 which semantics (sum or product) you want. The semantics of Maybe are
 clear: it's failure-and-prioritized-choice.

Are you sure? There are (at least) four Monoid instances for Maybe
[1]. With a direct instance for Maybe and its Dual you have only
covered two.

Erik

[1] https://byorgey.wordpress.com/2011/04/18/monoids-for-maybe/

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


Re: [Haskell-cafe] ANNOUNCE: partial-lens 0.0.1

2011-12-21 Thread Erik Hesselink
On Wed, Dec 21, 2011 at 16:39,  rocon...@theorem.ca wrote:
 On Wed, 21 Dec 2011, Erik Hesselink wrote:

 How does this relate to the Maybe lenses in fclabels [1]?

 Erik

 [1]
 http://hackage.haskell.org/packages/archive/fclabels/1.0.4/doc/html/Data-Label-Maybe.html


 It appears to be somewhere between similar and the same.

 *** Comparison of API

 Data.Label.Maybe.get corresponds to Data.Lens.Partial.getPL

 Data.Label.Maybe.set roughly corresponds to Data.Lens.Partial.trySetPL
 except that trySetPL will bail out early if the reference is null.  We can
 match the signature of set more precisely by:

 Data.Label.Maybe.set l v r ~ Data.Lens.Partial.trySetPL l r * pure v

 Data.Label.Maybe.modify would correspond to Data.Lens.Partial.tryModPL if I
 had implemented it ... which maybe I ought to.

 Data.Label.Maybe.embed corresponds to a composition of totalLens and
 maybeLens.  More specifically

 Data.Label.Maybe.embed l ~ Data.Lens.Partial.maybeLens .
 Data.Lens.Partial.totalLens l

 Data.Label.MaybeM.gets roughly corresponds to
 Data.Lens.Partial.Lazy.accessPlus except that accessPlus is particular to
 StateT because partial-lens is a Haskell 98 compliant package.  I need to
 write partial-lens-fd which will contain a function precisely corresponding
 to Data.Label.MaybeM.gets

 I don't have Data.Label.MaybeM.asks, because there was no corresponding
 functionality in data-lens.  We should probably add a version of this.

 *** Comparison of representation

 The usual differences between data-lens and fclabels applies to partial-lens
 as well.  The representation for data-lens and partial-lens allows modify to
 be done with one case analysis on a record since the getter and setters are
 combined into one coalgebra whereas in fclabels two case analysis must be
 done: one for the getter and one for the setter.  When chains of lenses are
 composed, I'm told the differences become more apparent.

 In partial-lens, the combination of getter and setter into a single
 coalgebraic operations means that the getter and setter are statically
 forced to return Nothing on the same record; but this is not enforced with
 the fclabels representation.

 That said, perhaps the MaybeLens from fclabels is trying to do something
 different.  I don't know what laws you expect to hold for the getter and
 setters of a maybe lens since it isn't documented (actually I appear to have
 also forgotten to document the coalgebra laws for a comonad in my package)
 so perhaps MaybeLens are intended to be more general than partial lenses.

 For example maybe a user wants to make it illegal to set the birth date to
 be greater than the death date in a record.  In this case getting the birth
 date will succeed, but setting will fail if the provided birth date out of
 bounds.  This is possible to write using MaybeLens, but is impossible with
 partial lenses since with partial-lenses either the reference is null,
 meaning getting and setting both fail, or it is not null which means that
 getting and setting both succeed.

Thanks for the detailed explanation! It seems they are indeed (almost)
the same, apart from the differences in representation.

The original motivation for the Maybe lenses in fclabels was accessing
record fields with Maybe types and composing these lenses (even in the
presence of multiple Maybes). It does not come from a category
theoretical starting point, hence no laws (yet). Your final example is
interesting, I'd never considered doing something like that.

Erik

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


Re: [Haskell-cafe] How hard is it to start a web startup using Haskell?

2011-12-19 Thread Erik Hesselink
At Silk [1] we use Haskell for the backend of our web application. The
frontend is Javascript with some functional aspects, and we have a
shallow ruby layer as a website (but not for the actual application).

Erik

[1] http://www.silkapp.com

On Mon, Dec 19, 2011 at 11:04, Ivan Perez ivanperezdoming...@gmail.com wrote:
 I'm actually trying to make a list of companies and people using Haskell
 for for-profit real world software development.

 I'd like to know the names of those startups, if possible.

 -- Ivan

 On 18 December 2011 18:42, Michael Snoyman mich...@snoyman.com wrote:
 On Sun, Dec 18, 2011 at 6:57 PM, Gracjan Polak gracjanpo...@gmail.com 
 wrote:

 Hi all,

 The question 'How hard is it to start a technical startup with Haskell?'
 happened a couple of times on this list. Sometimes it was in the form 'How 
 hard
 is to find Haskell programmers?' or 'Are there any Haskell jobs?'.

 I'd like to provide one data point as an answer:

 http://www.reddit.com/r/haskell/comments/ngbbp/haskell_only_esigning_startup_closes_second_angel/

 Full disclosure: I'm one of two that founded this startup.

 How are others doing businesses using Haskell doing these days?

 I don't run a startup myself, but I know of at least three startups
 using Haskell for web development (through Yesod), and my company is
 basing its new web products on Yesod as well. I think there are plenty
 of highly qualified Haskell programmers out there, especially if
 you're willing to let someone work remotely.

 Michael

 ___
 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

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


Re: [Haskell-cafe] Generating Code

2011-12-09 Thread Erik Hesselink
On Fri, Dec 9, 2011 at 20:45, L Corbijn aspergesoe...@gmail.com wrote:
 So I'm interested if there are other libraries that are more suitable
 to the task of generating haskell code for library use, and thus
 generate 'human readable' exported code (so no TH). I'm also
 interested in how other projects generate code for their packages.

Since you ask how other packages solve this problem, and since most
packages use template haskell, I have to ask: why can't you use
template haskell for this?

Another option (also not code generation, but very useful in reducing
boilerplate) is generic programming, for example using the 'regular'
package, or the new generics in GHC 7.2.

Erik

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


Re: [Haskell-cafe] Converting string to System.Time.ClockTime

2011-12-08 Thread Erik Hesselink
I'm not sure if you really need ClockTime (from old-time), but if you
don't, the types from the 'time' package are all parseable with
`parseTime` [1].

Erik

[1] 
http://hackage.haskell.org/packages/archive/time/latest/doc/html/Data-Time-Format.html#v:parseTime

On Thu, Dec 8, 2011 at 14:16, dokondr doko...@gmail.com wrote:
 Hi,
 What would be the simplest way to convert strings like Wed, 07 Dec 2011
 10:09:21 + to System.Time.ClockTime ?

 Thanks!



 ___
 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] How to get a file path to the program invoked?

2011-12-05 Thread Erik Hesselink
The operator / is an alias for `combine`, which the documentation says:

  Combine two paths, if the second path isAbsolute, then it returns the second.

In this case, / is absolute, so it is returned.

If you wish to add a trailing path separator, use `addTrailingPathSeparator`.

Erik

On Mon, Dec 5, 2011 at 15:53, dokondr doko...@gmail.com wrote:
 Balazs, thanks for your comments!
 The first comment works just fine.
 With / operator I get this:

 Main System.Environment.Executable System.FilePath /abc / /
 /

 Instead of getting /abc/ I get /. What am I doing wrong?

 On Mon, Dec 5, 2011 at 6:03 PM, Balazs Komuves bkomu...@gmail.com wrote:


 Two small comments:

 1) This should work on Windows too, if you just leave out the word Posix
 from the source:
 import System.FilePath (splitFileName)

 2) In general when dealing with paths, use the / operator (from
 System.FilePath)
 instead of ++ / ++

 Balazs


 On Mon, Dec 5, 2011 at 1:44 PM, dokondr doko...@gmail.com wrote:

 This is how I finally solved this problem for POSIX complaint system:

 --
 -- TestRun
 --
 module Main where
 import System.Cmd (rawSystem)
 import System.Directory (getCurrentDirectory)
 import System.Environment.Executable (ScriptPath(..), getScriptPath)
 import System.FilePath.Posix (splitFileName)

 main = do

   path - getMyPath
   putStrLn $ myPath =  ++ path
   let cmdLine = path ++ args.sh
   rawSystem cmdLine  [iphone, test-twitts.txt]

 {--
 data ScriptPath Source

 Constructors:
 Executable FilePath    it was (probably) a proper compiled executable
 RunGHC FilePath        it was a script run by runghc/runhaskell
 Interactive     we are in GHCi
 --}

 getMyPath = do
   curDir - getCurrentDirectory -- from System.Directory
   scriptPath  - getScriptPath -- from System.Environment.Executable
   let path = getMyPath' scriptPath curDir
   return path

 getMyPath' (Executable path) _ = fst (splitFileName path)
 getMyPath' (RunGHC path) _  = fst (splitFileName path)
 getMyPath' Interactive curDir = curDir++/



 ___
 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] writeFile: commitBuffer: invalid argument (Illegal byte sequence)

2011-12-04 Thread Erik Hesselink
What is the value of your LANG environment variable? Does it still
give the error if you set it to e.g. en_US.UTF-8?

Erik

On Sun, Dec 4, 2011 at 13:12, dokondr doko...@gmail.com wrote:
 Correct url of a bad string:
 http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen


 On Sun, Dec 4, 2011 at 3:08 PM, dokondr doko...@gmail.com wrote:

 Hi,
 In  GHC 7.0.3 / Mac OS X when trying to:

 writeFile  someFile (Hoping You Have A iPhone When I Do This) Lol Sleep
 Is When You Close These ---gt; \55357\56384

 I get:
 commitBuffer: invalid argument (Illegal byte sequence)

 The string I am trying to write can also be seen here:

 http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen

 It looks like 'writeFile' can not write unicode characters.
 Any workarounds?

 Thanks!
 Dmitri







 ___
 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] writeFile: commitBuffer: invalid argument (Illegal byte sequence)

2011-12-04 Thread Erik Hesselink
Yes, you can set the text encoding on the handle you're reading this
text from [1]. The default text encoding is determined by the
environment, which is why I asked about LANG.

If you're entering literal strings, see Albert Lai's answer.

Erik

[1] 
http://hackage.haskell.org/packages/archive/base/latest/doc/html/System-IO.html#g:23

On Sun, Dec 4, 2011 at 19:13, dokondr doko...@gmail.com wrote:
 Is there any other way to solve this problem without changing LANG
 environment variable?


 On Sun, Dec 4, 2011 at 8:27 PM, Erik Hesselink hessel...@gmail.com wrote:

 What is the value of your LANG environment variable? Does it still
 give the error if you set it to e.g. en_US.UTF-8?

 Erik

 On Sun, Dec 4, 2011 at 13:12, dokondr doko...@gmail.com wrote:
  Correct url of a bad string:
 
  http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen
 
 
  On Sun, Dec 4, 2011 at 3:08 PM, dokondr doko...@gmail.com wrote:
 
  Hi,
  In  GHC 7.0.3 / Mac OS X when trying to:
 
  writeFile  someFile (Hoping You Have A iPhone When I Do This) Lol
  Sleep
  Is When You Close These ---gt; \55357\56384
 
  I get:
  commitBuffer: invalid argument (Illegal byte sequence)
 
  The string I am trying to write can also be seen here:
 
 
  http://twitter.com/#!/search/Hoping%20You%20Have%20A%20iPhone%20When%20I%20Do%20This%20lang%3Aen
 
  It looks like 'writeFile' can not write unicode characters.
  Any workarounds?
 
  Thanks!
  Dmitri
 
 
 
 
 
 
 
  ___
  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] (no subject)

2011-11-28 Thread Erik Hesselink
On Mon, Nov 28, 2011 at 23:55, Willem O dub...@hotmail.com wrote:
 And I added this function:
 createPoint :: Int - Point
 createPoint x = Point x
 When I loaded the file containing all this into ghci and executed 'Vector $
 map createPoint [1..5]' the result was '(1, 2, 3, 4, 5)' (without the
 quotes).

Note that you do not need this function. You can just use the 'Point'
constructor:

map Point [1..5]

Erik

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


[Haskell-cafe] Proposed change to mime-mail

2011-11-23 Thread Erik Hesselink
Hi all,

I've found and solved a problem with mime-mail, and Michael Snoyman
asked me to send a request for feedback to -cafe, so here goes.

In short, the issue is with address headers containing 'special'
(non-ascii) characters. In mime-mail, these are automatically encoded
according to RFC 2047. However, the email address part of an address
header is not allowed to be encoded.

My patch adds 'from', 'to', 'cc' and 'bcc' fields to the Mail data
type, and creates correct headers from these fields. This does make
the Mail type a bit larger, so I've also added a smart constructor
with initializes these fields with empty lists (only 'from' is
required).

For more details, see my initial bug report [1] and my patches in the
pull request [2].

If you have any comments on this change, please let me know.

Regards,

Erik

[1] https://github.com/snoyberg/mime-mail/issues/5
[2] https://github.com/snoyberg/mime-mail/pull/6

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


Re: [Haskell-cafe] [Haskell] Dutch National FP Day 2012

2011-11-16 Thread Erik Hesselink
On Wed, Nov 16, 2011 at 16:19, Henning Thielemann
lemm...@henning-thielemann.de wrote:

 On Wed, 16 Nov 2011, Sean Leather wrote:

 (Sent on behalf of Doaitse Swierstra)

 Despite some last minute changes to the planning we are happy to announce
 that the next
 Dutch functional programming day will take place on January 6, 2012, at
 the university
 campus De Uithof of Utrecht University.

 In case you want to give a presentation please send title, speaker and
 abstract to
 doai...@swierstra.net before Dec 1.

 What is the language of the talks and the participants? English or Dutch?

In past years the language of the talks has always been English. Also,
most Dutch people speak English pretty well, I think.

Erik

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


Re: [Haskell-cafe] cabal install: Could not find module `Text.XML.HXT.Arrow'

2011-11-08 Thread Erik Hesselink
This is because hSimpleDB doesn't specify version ranges on its
dependencies, when it should. Since hxt changed its module structure
going from 9.0 to 9.1, hSimpleDB doesn't build against 9.0.

You can try to build it by adding '--constraint=hxt==9.0.\*' after
your cabal-install command. You can also ask the author to add version
ranges to the package.

Erik

On Tue, Nov 8, 2011 at 11:58, dokondr doko...@gmail.com wrote:
 Hi,
 On Mac OSX, ghc-6.12.3, I have successfully installed the 'hxt' package:
 http://hackage.haskell.org/package/hxt-8.5.2

 Registering hxt-9.1.4...
 Installing library in /Users/user/.cabal/lib/hxt-9.1.4/ghc-6.12.3

 Now when I try to install hSimpleDB
 (http://hackage.haskell.org/package/hSimpleDB) I get the following error:

 cabal install hSimpleDB
 ...
 Registering HTTP-4000.0.9...
 Installing library in /Users/user/.cabal/lib/HTTP-4000.0.9/ghc-6.12.3
 Registering HTTP-4000.0.9...
 Configuring hSimpleDB-0.3...
 Preprocessing library hSimpleDB-0.3...
 Building hSimpleDB-0.3...

 src/Network/AWS/Authentication.hs:47:7:
     Could not find module `Text.XML.HXT.Arrow':
   Use -v to see a list of the files searched for.
 cabal: Error: some packages failed to install:
 hSimpleDB-0.3 failed during the building phase. The exception was:
 ExitFailure 1

 Any ideas how to solve this?

 Thanks!
 Dmitri

 ___
 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 install: Could not find module `Text.XML.HXT.Arrow'

2011-11-08 Thread Erik Hesselink
On Tue, Nov 8, 2011 at 12:16, Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com wrote:
 On 8 November 2011 22:10, Erik Hesselink hessel...@gmail.com wrote:
 This is because hSimpleDB doesn't specify version ranges on its
 dependencies, when it should. Since hxt changed its module structure
 going from 9.0 to 9.1, hSimpleDB doesn't build against 9.0.

 You can try to build it by adding '--constraint=hxt==9.0.\*' after
 your cabal-install command. You can also ask the author to add version
 ranges to the package.

 Is the escape needed if you're using single quotes?

I don't know. I always escape *s in shell commands to be sure the
shell doesn't expand them, but in most of the cases, it probably works
without them. It will likely even work without quotes and without the
escape, unless you have files matching the pattern.

Erik

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


Re: [Haskell-cafe] SMP parallelism increasing GC time dramatically

2011-10-10 Thread Erik Hesselink
On Mon, Oct 10, 2011 at 16:44, Tom Thorne thomas.thorn...@gmail.com wrote:
 thanks! I just tried setting -A32M and this seems to fix the parallel GC
 problems, I now get a speedup with parallel GC on and performance is the
 same as passing -qg. I had tried -H before and it only made things worse,
 but -A seems to do the trick.

You might be able to use ghc-gc-tune [1] to find the right settings
for -A and -H.

Erik

[1] http://hackage.haskell.org/package/ghc-gc-tune

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


Re: [Haskell-cafe] DSL for data definition (e.g. compiling Haskell type defs into Google's protocol buffers type defs)

2011-10-04 Thread Erik Hesselink
On Tue, Oct 4, 2011 at 20:33, Karel Gardas karel.gar...@centrum.cz wrote:
 data PersonType = Person {
        id :: Int
        , name :: String
        , email :: Maybe String
        }
        deriving (Show, Data, Typeable)


 so I have `PersonType' as type constructor and Person as value constructor
 (or data constructor) -- speaking using terms from Real World Haskell,
 Chapter 3[1]. And now I see that none of typeOf/dataTypeOf/toContr is
 applicable to *type constructor* but all are applicable to *value/data
 constructor*. Ditto happen when testing Color versus RED, GREEN, BLUE. At
 least GHCi complains this way:

 *Main typeOf Color

 interactive:0:8: Not in scope: data constructor `Color'
 *Main typeOf PersonType

 interactive:0:8: Not in scope: data constructor `PersonType'

 But, I'd like to start processing of data definition from the *type
 constructor*. So:

 emit_proto PersonType 1
 emit_proto Color 1

 Is that possible at all? I mean in the scope/context of GHC's
 Data/Data.Data/Data.Typeable etc. modules. (w/o considering TH now).

A definition of 'typeOf' is not supposed to use its argument, since
the normal way to call it is to pass undefined. The documentation
says:

The value of the argument should be ignored by any instance of
Typeable, so that it is safe to pass undefined as the argument. 

So you should call it like:

typeOf (undefined :: PersonType).

Erik

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


Re: [Haskell-cafe] which tags program should I use?

2011-09-26 Thread Erik Hesselink
I use hothasktags [1] which works very well. The only problems are
sometimes with obscure extensions, where haskell-src-exts (which
hothasktags uses) can't parse the file, but that happens very rarely.

Regarding speed: it takes 2-3 s on about 250 source files totaling
about 25000 lines on my laptop.

Regards,

Erik

[1] https://github.com/luqui/hothasktags/

On Sun, Sep 25, 2011 at 15:41, Henry Laxen nadine.and.he...@pobox.com wrote:
 Dear Group,

 I have a simple question, that as far as I can tell, has never really
 been well answered.  I would like to generate TAGS files for haskell
 source.  Reading the http://www.haskell.org/haskellwiki/Tags page
 suggests using :etags in GHCI or hasktags, or gasbag.  Of the three,
 hasktags comes closest to working but it has (for me) a major
 inconvenience, namely it finds both function definitions and type
 signatures, resulting in two TAGS entries such as:

 ./Main.hs,63
 module Main where 6,7
 main :: 24,25
 main = 25,26

 Now when I do an emacs find-tag (I use icicles) I will always have to
 choose which tag I want to visit, and the completion buffer contains
 something like:

 main ::
 hs/Main.hs

 main =
 hs/Main.hs


 Granted, this is a minor (and very specialized) complaint, but if
 hasktags were to select only ONE of either the type signature (my
 first choice) or the function definition, (if no type signature) this
 annoyance would disappear.

 I also tried using etags, which I think would work, but it seems to
 have one killer bug (feature), namely that it dies if it finds an
 uninterpreted import:

  when (not is_interpreted) $
    let mName = GHC.moduleNameString (GHC.moduleName m) in
    ghcError (CmdLineError (module ' ++ mName ++ ' is not interpreted))

 I think it would work much better if it just warned you, instead of
 dying.  This makes it unusable any time you import something
 precompiled.

 Now some looking at the README of hasktags leads me to:

 In the past this tool was distributed with ghc. I forked and added some
 features.  hasktags itself was moved out of the ghc repository. Then I only
 verified that my fork finds at least as much tags as the one forked by
 Igloo.

 That makes me feel a little queasy.

 A google search for hasktags igloo turns up
 http://hackage.haskell.org/trac/ghc/ticket/1508
 whose title is hasktags program needs replacement
 which makes me feel even more queasy.

 So I guess my question is, what are us disciples of the one true
 editor to do?  Thanks in advance for you sage advice.

 Best wishes,
 Henry Laxen




 ___
 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] ANN: cabal-ghci 0.1

2011-09-10 Thread Erik Hesselink
On Fri, Sep 9, 2011 at 22:17, Jason Dagit dag...@gmail.com wrote:
 On Thu, Sep 8, 2011 at 11:06 PM, Etienne Laurin etie...@atnnn.com wrote:
 Hello fellow hackers.

 Here is a helpful package I wrote to ease the development of projects
 using cabal.

 It includes a :cabalset ghci command to set ghci options for your
 project, and a cabal-ghci executable to launch ghci with those
 options.

 Is :cabalset custom per project or could I put the same things in my ~/.ghci?

Did you know you can also put a .ghci file in your project dir, and if
you start ghci from that dir, it will also load that file? I think
that allows you to replicate some of the functionality of this tool,
since it allows per project ghci options.

Erik

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


Re: [Haskell-cafe] compiler pragma's

2011-09-10 Thread Erik Hesselink
On Fri, Sep 9, 2011 at 23:41, Vasili I. Galchin vigalc...@gmail.com wrote:
    Is there a list of compiler pragmas? Specifically I am looking at how to
 specify more than one type variable in a class definition. Also I have
 forgotten the meta syntax for specifying a pragma ... some kind of Haskell
 comment?

If you're using GHC, there is a list of language extensions in the
user's guide chapter 7 [1]. Specifically, 7.13 specifies the language
pragma's. To turn on a language extension, you use the LANGUAGE pragma
with the specific extension(s) you want. In this case, you want
MultiParamTypeClasses, section 7.6.1.1. So the exact syntax will be:

{-# LANGUAGE MultiParamTypeClasses #-}

Put this at the top of your source file.

Note that the link is to the documentation for the latest version of
GHC (7.2.1 as of this writing). There are also links to specific
version, that might be more appropriate depending on the version of
GHC you have.

Erik

[1] 
http://haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html

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


  1   2   >