Re: [Haskell-cafe] How many Haskell Engineer I/II/IIIs are there?

2010-02-11 Thread Erik Hesselink
On Wed, Feb 10, 2010 at 16:59, Jason Dusek jason.du...@gmail.com wrote:
  I wonder how many people actually write Haskell,
  principally or exclusively, at work?

We (typLAB) use Haskell. There's four of us, but only two actually
program Haskell, and not exclusively. We also use Javascript in the
browser (though we use functional programming techniques there as
well).

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


Re: [Haskell-cafe] Perform a research a la Unix 'find'

2010-08-22 Thread Erik Hesselink
I've used the FileManip package for this. It works fine for my
purposes. I have no idea what the performance is, though, beyond 'good
enough not to care at the moment'.

Erik

On Sun, Aug 22, 2010 at 17:32, Yves Parès limestr...@gmail.com wrote:
 Hello,

 I would like to recode in Haskell a piece of bash program that uses find.
 The advantage of find is that it is quite easy to use and fast.
 Is there a package that let us access to find-like functionnalities, with
 similar performances? Or at least some C functions that could be used
 through the FFI?
 (I would like to avoid to recur through directories and match files myself,
 I tried it and the search lasts for ages).


 ___
 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] Statically tracking validity - suggestions?

2010-08-31 Thread Erik Hesselink
On Tue, Aug 31, 2010 at 08:24, strejon strej...@yahoo.com wrote:

 Hello. I'm using Haskell to write a specification for some software. The
 software uses certificates (standard X.509 certificates) and stores user
 name information in the Subject's CommonName field.

 The X.509 standard doesn't actually require the presence of a CommonName
 field so the contents of the Subject section (with the rest of the fields
 omitted) are just represented by a Maybe User_Name.

 import Data.List (find, concat)
 import Data.Maybe (fromJust, isJust)

 type User_Name    = String
 type Public_Key   = Integer
 data Subject_Name = Subject_Name (Maybe User_Name) deriving (Show, Eq)

 data Certificate = Certificate {
   certificate_subject :: Subject_Name,
   certificate_key     :: Public_Key,
   certificate_issuer  :: String,
   certificate_serial  :: Integer
 } deriving (Show, Eq)

 This is all well and good, but the problem is that the validity of
 certificates isn't tracked statically and I have to use the following
 as guards on all functions that only expect valid certificates (and
 inevitably handle cases that I know can't actually happen but
 have to be handled in pattern matching and the like, bloating
 the specification):

 user_name :: Subject_Name - Maybe User_Name
 user_name (Subject_Name name) = name

 is_valid :: Certificate - Bool
 is_valid = isJust . user_name . certificate_subject

 I'm aware of phantom types and the like, but I've been unable to
 work out how to use them (or another type system extension)
 to properly track validity on the type level. I'd want something
 like:

 validate :: Certificate Possibly_Valid - Maybe (Certificate Valid)

 With later functions only accepting values of type Certificate Valid.

 Is there a simple way to do this?

If you want to use types instead of modules and hiding as Chris
suggested, you can use a type index like this:

{-# LANGUAGE EmptyDataDecls, GADTs, KindSignatures #-}
data Nothing
data Just a

data Subject :: * - * where
  NoName :: Subject Nothing
  Name   :: String - Subject (Just String)

data Certificate a = Certificate
  { subject :: Subject a }

validate :: Certificate a - Maybe (Certificate (Just String))
validate c =
  case subject c of
NoName - Nothing
Name n - Just c

A Certificate (Just String) now always holds a name, and a
Certificate Nothing doesn't. A Certificate a can hold either.

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


Re: [Haskell-cafe] Re: Scraping boilerplate deriving?

2010-09-14 Thread Erik Hesselink
Yes, if you use template haskell, all top level functions and values
have to be defined before you use them.

Erik

On Tue, Sep 14, 2010 at 18:11, Kevin Jardine kevinjard...@gmail.com wrote:
 Hmm - It seems to work if the code is defined before my main function
 and not after it.

 Does this have to do with TH being part of the compile process and so
 the order matters?

 Kevin

 On Sep 14, 6:03 pm, Kevin Jardine kevinjard...@gmail.com wrote:
 Thanks Serguey!

 The library code compiles, but when I try to use it in client code:

 a. I get:

 Not in scope: type constructor or class 'A'

 and even stranger,

 b. GHC cannot find any of my code after the

 $(mkNewType A)

 and claims that all the functions I defined there are also not in
 scope.

 Any ideas?

 The CPP solution works but Template Haskell is definitely cooler, so
 it would be great to get this to work!

 Kevin

 On Sep 14, 2:29 pm,  Zefirov sergu...@gmail.com wrote:

  2010/9/14 Kevin Jardine kevinjard...@gmail.com:

   I would like to use some macro system (perhaps Template Haskell?) to
   reduce this to something like

   defObj MyType

   I've read through some Template Haskell documentation and examples,
   but I find it intimidatingly hard to follow. Does anyone has some code
   suggestions or pointers to something similar?

  The solutions first:
  -
  {-# LANGUAGE TemplateHaskell #-}

  module T(mkNewType) where

  import Language.Haskell.TH

  decls = [d|newtype TempDecl = TempDecl Int deriving (Eq,Ord,Show)|]
  decl = do
          [d] - decls
          runIO $ print d -- just to show inetrnals
          return d

  mkNewType :: String - Q [Dec]
  mkNewType n = do
          d - decl
          let name = mkName n
          return $ (\x - [x]) $ case d of
                  (NewtypeD cxt _ argvars (NormalC _ args) derivings) -
                          NewtypeD cxt name argvars (NormalC name args) 
  derivings
  --
  I took perfectly valid declaration, dissected it using case analysis
  and changed relevant parts.

  And an example client:
  -
  {-# LANGUAGE TemplateHaskell #-}

  import T

  $(mkNewType A)
  -
  It all work together.

  I studied how to use Template Haskell that way: I obtained
  declarations of what I need, printed them and looked through
  documentation for relevant data types and constructors. It's not
  harder that any other library in Haskell, actually.
  ___
  Haskell-Cafe mailing list
  haskell-c...@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe

 ___
 Haskell-Cafe mailing list
 haskell-c...@haskell.orghttp://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] Re: Non-existing types in existential quantification?

2010-10-03 Thread Erik Hesselink
On Sun, Oct 3, 2010 at 14:10, Daniel Fischer daniel.is.fisc...@web.de wrote:
 On Sunday 03 October 2010 10:43:24, Henning Thielemann wrote:
 On Sun, 3 Oct 2010, Ben Franksen wrote:
  Christopher Done wrote:
  Consider the following program:
 
  main = putStrLn $ show $ length [undefined :: a,undefined :: b]
 
  A concrete type of the element in list doesn't need to be determined
  at runtime, or any time. a unifies with b, and that unifies with x in
  length :: [x] - Int.
 
  A simpler example is
 
   main = print Nothing

 This seems to be a different example, because GHCi -Wall says that the
 type variable defaults to (). Thus 'Nothing' has monomorphic type at
 runtime. The difference is certainly that 'print' requires a Show
 instance, whereas Christopher's example does not require a type
 constraint.

 Yup.

 Prelude print $ length [undefined :: a, undefined :: b]
 2
 Prelude print $ length [undefined :: a, undefined :: Num b = b]

 interactive:1:32:
    Warning: Defaulting the following constraint(s) to type `Integer'
             `Num a'
               arising from an expression type signature at
 interactive:1:32-54
    In the expression: undefined :: (Num b) = b
    In the first argument of `length', namely
        `[undefined :: a, undefined :: (Num b) = b]'
    In the second argument of `($)', namely
        `length [undefined :: a, undefined :: (Num b) = b]'
 2
 Prelude print $ length [undefined :: a, undefined :: Num b = c - b]

 interactive:1:32:
    Warning: Defaulting the following constraint(s) to type `Integer'
             `Num b'
               arising from an expression type signature at
 interactive:1:32-59
    In the expression: undefined :: (Num b) = c - b
    In the first argument of `length', namely
        `[undefined :: a, undefined :: (Num b) = c - b]'
    In the second argument of `($)', namely
        `length [undefined :: a, undefined :: (Num b) = c - b]'
 2

 At runtime, a type variable has to be either unconstrained or instantiated
 with a concrete type?

GHC has the 'Any' type, and the docs state:

It's also used to instantiate un-constrained type variables after
type checking. [1]

So I guess at least for GHC, all type variables are instantiated after
type checking?

Regards,

Erik

[1] 
http://www.haskell.org/ghc/docs/6.12.2/html/libraries/ghc-prim-0.2.0.0/GHC-Prim.html#t%3AAny
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Systematic treatment of static arguments

2010-10-17 Thread Erik Hesselink
On Sat, Oct 16, 2010 at 21:39, Stephen Tetley stephen.tet...@gmail.com wrote:
 Hello list

 The Monad and Applicative instances for functions are equivalent to
 the respective Reader vesions (I use equivalent along the lines of -
 operationally the same but without the type distinction / newtype).
 There is also the Monoid instance for functions which is pretty slick.

 Has anyone looked at variations with two or more static arguments though?

 For example mappend with two static arguments needs to be defined
 either as a new function:

 mappendR2 :: Monoid a = (r1 - r2 - a) - (r1 - r2 - a) - r1 - r2 - a
 mappendR2 f g = \x y - f x y `mappend` g x y

 or an overlapping instance:

 instance Monoid a = OPlus (r1 - r2 - a) where
   f `mappend` g = \x y - f x y `mappend` g x y

I think you can just use the original instance for Monoid for this. It declares

instance Monoid b = Monoid a - b

since 'b' can itself be a function (and r1 - r2 - a is parenthesized
as r1 - (r2 - a)), this will work. 'b' can be instantiated to (r2 -
a) in your case, which is a Monoid due to another instance for
functions, this time with 'b' instantiated to 'a'.

This doesn't work for Reader, though. There, you're probably easier
off using just a tuple, or, even better, a record, where you can use
the 'asks' function to extract a single component.

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


Re: [Haskell-cafe] concurrency vs. I/O in GHC

2010-10-28 Thread Erik Hesselink
On Wed, Oct 27, 2010 at 23:09, Andrew Coppin
andrewcop...@btinternet.com wrote:
 On 27/10/2010 05:00 PM, John Lato wrote:

 I am somewhat surprised that all capabilities must be ready for GC; I
 thought with the parallel GC that wouldn't be necessary.  But I don't know
 much about GC implementations so I try not to let their behavior surprise me
 too much.

 GHC has a _parallel_ GC implementation, meaning that the GC event runs in
 parallel on several cores. But it does not (yet) have _concurrent_ GC,
 meaning that a GC event can happen at the same time as Haskell threads are
 running. (Basically, which Haskell code running, the references between
 objects could change while the GC engine is trying to analyse them, which
 would be Bad.) I understand that the developers are actively working on
 fixing this, since it can sometimes have a significant effect on the
 performance of multicore programs...

I thought that young generations could be GC'ed while other threads
were running, while collecting the old generation required
synchronizing all threads. This seems to be what is shown on
http://hackage.haskell.org/trac/ghc/blog/new-gc-preview as well.

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


Re: [Haskell-cafe] concurrency vs. I/O in GHC

2010-10-28 Thread Erik Hesselink
On Thu, Oct 28, 2010 at 19:06, Andrew Coppin
andrewcop...@btinternet.com wrote:
 On 28/10/2010 09:25 AM, Erik Hesselink wrote:

 On Wed, Oct 27, 2010 at 23:09, Andrew Coppin
 andrewcop...@btinternet.com  wrote:

 GHC has a _parallel_ GC implementation, meaning that the GC event runs in
 parallel on several cores. But it does not (yet) have _concurrent_ GC,
 meaning that a GC event can happen at the same time as Haskell threads
 are
 running. (Basically, which Haskell code running, the references between
 objects could change while the GC engine is trying to analyse them, which
 would be Bad.) I understand that the developers are actively working on
 fixing this, since it can sometimes have a significant effect on the
 performance of multicore programs...

 I thought that young generations could be GC'ed while other threads
 were running, while collecting the old generation required
 synchronizing all threads. This seems to be what is shown on
 http://hackage.haskell.org/trac/ghc/blog/new-gc-preview as well.

 I expect it to land in GHC HEAD in a few months time, and it should be in
 the autumn 2011 major release of GHC.

 In other words, this isn't how GHC works now, it's how some future version
 will work.

Ah, sorry, I missed that.

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


Re: [Haskell-cafe] Non-hackage cabal source

2010-11-03 Thread Erik Hesselink
On Wed, Nov 3, 2010 at 06:49, Tony Morris tonymor...@gmail.com wrote:
 I am trying to set up an apache server as an additional source to
 hackage for haskell packages.

 I have added to my ~/.cabal/config file:
 remote-repo: myhackage:http://myhackage/packages

Shouldn't that be:

 remote-repo: myhackage:http://myhackage/packages/archive

That's what the normal hackage entry says, and what I use for our own
local hackage.

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


Re: Better Records was Re: [Haskell-cafe] Type Directed Name Resolution

2010-11-15 Thread Erik Hesselink
On Fri, Nov 12, 2010 at 22:48, Jonathan Geddes
geddes.jonat...@gmail.com wrote:
 Records do leave quite a bit to be desired. But does anybody actually have a
 concrete alternative proposal yet?

 A few months ago I proposed a couple of extensions [1] on -cafe.

[snip]

  Consider what this would do for nested updates:

UpdateTripleInner :: (Inner-Inner) - MyTriplyNestedRecord - 
MyTriplyNestedRecord
UpdateTripleInner f = \{inner1 = \{inner2 = \{inner3 = f }}}

 I cringe to imagine what the equivalent is in current Haskell syntax.
 Anyone want to try it? Not me!

You can do this very conveniently already using the fclabels package:

updateTrippleInner = modL (inner3 . inner2 . inner1)

Here, inner1/2/3 are not record fields, but Lenses. You have to
construct the lenses themselves, but this is very easy, and can be
automated using Template Haskell.

Other packages like data-accessor have similar functionality.

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


Re: [Haskell-cafe] About Fun with type functions example

2010-11-18 Thread Erik Hesselink
On Thu, Nov 18, 2010 at 20:17, Arnaud Bailly arnaud.oq...@gmail.com wrote:
 Hello,
 I am trying to understand and use the Nat n type defined in the
 aforementioned article. Unfortunately, the given code does not compile
 properly:

[snip]

 instance (Nat n) = Nat (Succ n) where
  toInt   _ = 1 + toInt (undefined :: n)

[snip]

 And here is the error:

 Naturals.hs:16:18:
    Ambiguous type variable `n' in the constraint:
      `Nat n' arising from a use of `toInt' at Naturals.hs:16:18-39
    Probable fix: add a type signature that fixes these type variable(s)

You need to turn on the ScopedTypeVariables extension (using {-#
LANGUAGE ScopedTypeVariables #-} at the top of your file, or
-XScopedTypeVariables at the command line). Otherwise, the 'n' in the
class declaration and in the function definition are different, and
you want them to be the same 'n'.

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


Re: [Haskell-cafe] Why does cabal unnecessarily reinstall dependencies?

2010-11-23 Thread Erik Hesselink
It might be that it both your own package and the dependencies cabal
tries to reinstall all depend on some package P. If the dependencies
are installed depending on P version 1, but to satisfy all
dependencies for your own package, cabal needs them to depend on P
version 2, cabal will reinstall them (possibly breaking other packages
that depend on them; is this a bug?)

You can see if this is the case by running 'cabal install --dry-run -v'.

Erik

On Mon, Nov 22, 2010 at 22:26, Martijn van Steenbergen
mart...@van.steenbergen.nl wrote:
 Hello cafe,

 When I want to locally install my own package through cabal install it
 tries to reinstall dependencies convertible-1.0.9.1, HDBC-2.2.6.1 and
 HDBC-mysql-0.6.3 even though they are already installed (and work fine). Why
 does it do this?

 cabal-install version 0.8.2
 using version 1.8.0.2 of the Cabal library
 Mac OS Leopard

 Thanks,

 Martijn.
 ___
 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] Transparent identity instances

2010-11-28 Thread Erik Hesselink
On Sun, Nov 28, 2010 at 15:59, Jafet jafet.vi...@gmail.com wrote:
 But using this instance becomes unwieldy. If using Identity was
 transparent, eg. if it was a type synonym

 {-# LANGUAGE TypeSynonymInstances #-}
 type Identity a = a
 instance Applicative Identity where
   -- something like
   pure a = a
   f * a = f a

 But GHC does not accept type synonym instances unless they are fully applied.

 Is it sound for such an instance to exist? If so, how might it be defined?

Type synonym instances are nothing special, they are just shorthand
for writing an instance for the type they are a synonym for. So an
instance for 'Identity a' would actually be an instance for 'a' (which
isn't such a good idea). An instance for 'Identity' is indeed not
possible.

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


Re: [Haskell-cafe] Storables and Ptrs

2010-12-06 Thread Erik Hesselink
 This can be used to call into C code expecting pointer input or output
 types to great effect:

 wrapperAroundForeignCode :: InputType - IO OutputType
 wrapperAroundForeignCode in =
  alloca $ \inPtr -
  alloca $ outPtr - do
    poke inPtr in
    c_call inPtr outPtr
    peek outPtr

There is also 'with' (:: Storable a = a - (Ptr a - IO b) - IO b),
which is exactly the combination of 'alloca' and 'poke' you use on
'in'.

Erik

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


Re: [Haskell-cafe] Missing Functor instances in GHC 7?

2010-12-10 Thread Erik Hesselink
On Fri, Dec 10, 2010 at 09:33, Simon Peyton-Jones simo...@microsoft.com wrote:
 | Interestingly, if I import only Control.Applicative from within GHCi, it
 | does not find the instances defined in Control.Monad.Instances although
 | this module is imported in Control.Applicative. On the other hand, if I
 | write a file containing the line 'import Control.Applicative' and load
 | this file in GHCi then the instances from Control.Monad.Instances are
 | visible.
 |
 | Apparently, importing a module in GHCi differs from importing it in a
 | Haskell file and loading this into GHCi.

 I don't believe that should happen, depending on exactly what you mean by 
 importing a module in GHCi.

I see this as well. Using import Control.Applicative in ghci doesn't
seem to bring the instance into scope, while using :m
+Control.Applicative does. See the log below. Note that the instance
really isn't available, i.e. it's not a problem with :i.

GHCi, version 7.0.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude :i Functor
class Functor f where
  fmap :: (a - b) - f a - f b
  (GHC.Base.$) :: a - f b - f a
-- Defined in GHC.Base
instance Functor Maybe -- Defined in Data.Maybe
instance Functor [] -- Defined in GHC.Base
instance Functor IO -- Defined in GHC.Base
Prelude import Control.Applicative
Prelude Control.Applicative :i Functor
class Functor f where
  fmap :: (a - b) - f a - f b
  ($) :: a - f b - f a
-- Defined in GHC.Base
instance Functor ZipList -- Defined in Control.Applicative
instance Monad m = Functor (WrappedMonad m)
  -- Defined in Control.Applicative
instance Functor (Const m) -- Defined in Control.Applicative
instance Functor Maybe -- Defined in Data.Maybe
instance Functor [] -- Defined in GHC.Base
instance Functor IO -- Defined in GHC.Base
Prelude Control.Applicative :m +Control.Applicative
Prelude Control.Applicative :i Functor
class Functor f where
  fmap :: (a - b) - f a - f b
  ($) :: a - f b - f a
-- Defined in GHC.Base
instance Functor (Either a) -- Defined in Control.Monad.Instances
instance Functor ((-) r) -- Defined in Control.Monad.Instances
instance Functor ((,) a) -- Defined in Control.Monad.Instances
instance Functor ZipList -- Defined in Control.Applicative
instance Monad m = Functor (WrappedMonad m)
  -- Defined in Control.Applicative
instance Functor (Const m) -- Defined in Control.Applicative
instance Functor Maybe -- Defined in Data.Maybe
instance Functor [] -- Defined in GHC.Base
instance Functor IO -- Defined in GHC.Base
Prelude Control.Applicative

Erik

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


Re: [Haskell-cafe] handling multiple versions of a data structure

2010-12-17 Thread Erik Hesselink
I've recently been playing with code for versioning data types. It's
based on happstacks implementation, but uses type families to make it
more modular. I've got some proof of concept code on github [1]. We're
also writing a small library based on this at typLAB, which we'll
probably release as well.

Erik

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

On Thu, Dec 16, 2010 at 19:26, Dmitry V'yal akam...@gmail.com wrote:
 Greetings,

 while developing my neural net simulator I stumbled upon a problem.

 I have a data type NeuralNet and use Show and Read instances for saving and
 loading configurations. As time passed, I changed the data type, so the
 program can no longer load files saved in previous versions.

 I want fix it. My current idea looks as follows. I'm going to create a bunch
 of types NN1, NN2, NN3..NNn for different versions and write converters c12
 :: N1 - N2, c23 :: N2 - N3 and so on.

 But how to organize the whole process of parsing String into NNn so it's
 easy to change formats?
 Something based on using a list of parsers
 [read, c43 . read, c43 . c23 . read, c43, c23 . c12 . read, c43 . c32 . c21
 . read]

 looks rather verbose and grows quadratically with N.

 I'm sure there must be a more elegant way. Any ideas?

 Dmitry

 ___
 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] handling multiple versions of a data structure

2010-12-18 Thread Erik Hesselink
No, I don't think so. It uses some extensions, but happstack-data
already does, so that shouldn't be a problem. We don't have a
releasable library yet, but when we do, it will have a versioned
binary implementation, just like happstack-data does now. Perhaps even
binary compatible with it, though I'm not sure about that.

Erik

On Sat, Dec 18, 2010 at 19:11, Jeremy Shaw jer...@n-heptane.com wrote:
 Nice.

 Do you think there is any reason we would not be able to / want to use it
 with happstack ? I would love happstack-data to 'go away' and just use some
 library from hackage which does the same thing.

 - jeremy

 On Dec 17, 2010, at 3:57 AM, Erik Hesselink wrote:

 I've recently been playing with code for versioning data types. It's
 based on happstacks implementation, but uses type families to make it
 more modular. I've got some proof of concept code on github [1]. We're
 also writing a small library based on this at typLAB, which we'll
 probably release as well.

 Erik

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

 On Thu, Dec 16, 2010 at 19:26, Dmitry V'yal akam...@gmail.com wrote:

 Greetings,

 while developing my neural net simulator I stumbled upon a problem.

 I have a data type NeuralNet and use Show and Read instances for saving
 and
 loading configurations. As time passed, I changed the data type, so the
 program can no longer load files saved in previous versions.

 I want fix it. My current idea looks as follows. I'm going to create a
 bunch
 of types NN1, NN2, NN3..NNn for different versions and write converters
 c12
 :: N1 - N2, c23 :: N2 - N3 and so on.

 But how to organize the whole process of parsing String into NNn so it's
 easy to change formats?
 Something based on using a list of parsers
 [read, c43 . read, c43 . c23 . read, c43, c23 . c12 . read, c43 . c32 .
 c21
 . read]

 looks rather verbose and grows quadratically with N.

 I'm sure there must be a more elegant way. Any ideas?

 Dmitry

 ___
 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] ANNOUNCE: yackage 0.0.0

2010-12-27 Thread Erik Hesselink
There is also the hackage 2.0 code [1]. This can be easily
cabal-installed, and added as an extra remote-repo to your
.cabal/config file. We've set this up at typLAB [2], and it's working
great. Cabal upload doesn't support multiple remote repo's, but we've
created a small deployment utility to quickly deploy to our own
hackage. By careful version number management, you can also create
local forks of hackage packages.

Erik

[1] http://hackage.haskell.org/trac/hackage/wiki/HackageDB
[2] http://www.typlab.com

On Mon, Dec 27, 2010 at 17:53, David Leimbach leim...@gmail.com wrote:
 This is very interesting.  I was thinking if this could work like an
 overlayed namespace on top of Hackage, rather than a complete override,
 that it would be a very interesting way to fork Hackage so it does what
 you want, transparently, and as a proxy.  Is that actually how it works
 though?  (It might be that I've not had my coffee yet, but I'm a little
 fuzzy on that point).
 While the Haskell-platform is a great stabilizing technology for the Haskell
 community and gives a nice warm fuzzy feeling to those who want to try it in
 commercial settings, it's not always true that it provides enough
 functionality for everyone's needs, and being able to somewhat modify what's
 available on Hackage could be very valuable.
 Dave

 On Mon, Dec 27, 2010 at 8:41 AM, Michael Snoyman mich...@snoyman.com
 wrote:

 Hi all,

 I was speaking with my coworker Yitz[1] about a project he's working
 on. Basically, he's going to end up with about 16 cabal packages that
 are not going to be deployed to Hackage, and wanted us to set up a
 Hackage server for our company to deploy these kinds of things.
 However, getting all the pieces of Hackage aligned properly for such a
 simple use case seemed a bit overkill.

 I then realized that I had the exact same problem during Yesod
 development: before I make a major release, I usually end up with
 about 10-15 packages that are not yet live on Hackage. It gets to be a
 real pain when suddenly wai-extra is depending on network 2.3 and
 authenticate requires network 2.2, and suddenly I need to manually
 recompile 10 packages.

 So I decided to write up a simple web service to act as a local
 Hackage server. It has no security (anyone with access can upload a
 package), doesn't build haddocks, doesn't show package descriptions,
 etc. All it does is:

 Show a list of uploaded packages/versions
 Links to the tarballs
 Allows you to upload new versions, which will automatically overwrite
 existing packages
 Provides the 00-index.tar.gz file needed by cabal-install, as well as
 the tarballs for all the packages

 In order to use this, just do the following:

 cabal install yackage
 run yackage
 Upload your packages
 Add remote-repo: yackage:http://localhost:3500/ to your ~/.cabal/config
 file
 cabal update
 Install your packages are usual

 You'll need to leave yackage running whenever you want to run an
 update or download new packages. A few other usage notes:

 If you overwrite a package, your cache folder will still have the old
 version. You might want to just wipe our your cache folder on each
 usage.
 Running cabal update will download the update for both yackage and the
 main hackage server; the latter can be a long process depending on
 your internet connection.

 Here's a little shell script that will disable the Hackage repo, wipe
 our the Yackage cache, update and re-enable the Hackage repo:

 #!/bin/sh

 CABAL_DIR=~/.cabal

 cp $CABAL_DIR/config $CABAL_DIR/config.sav
 sed 's/^remote-repo: hackage/--remote-repo: hackage/' 
 $CABAL_DIR/config.sav  $CABAL_DIR/config
 rm -rf $CABAL_DIR/packages/yackage
 cabal update
 cp $CABAL_DIR/config.sav $CABAL_DIR/config

 I hope others find this tool useful.

 Michael

 [1] http://www.haskellers.com/user/Yitz_Gale/

 ___
 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] Unknown symbol `__dso_handle' with Template Haskell and wxHaskell

2010-12-27 Thread Erik Hesselink
We had this problem with a binding to a C++ library (through a C
wrapper). GHCi and cabal didn't work, but ghc --make did. How are you
compiling exactly when you get this error? This is somehow related to
TH, without it, at least cabal also works. I'm not sure about GHCi.
There's also a relevant bug in the GHC trac, but I can't seem to find
it now.

Erik

On Sat, Dec 25, 2010 at 18:41, Alexander Bau a...@imn.htwk-leipzig.de wrote:
 Hi,

 I am using Template Haskell and wxHaskell [1]. When Graphics.UI.WX is
 loaded during THs code generation, I get the following error:

 ...
 Loading package wxdirect-0.12.1.3 ... linking ... done.
 ghc: /usr/local/lib/wxcore-0.12.1.6/ghc-6.12.3/HSwxcore-0.12.1.6.o:
 unknown symbol `__dso_handle'
 Loading package wxcore-0.12.1.6 ...
 linking ... ghc: unable to load package `wxcore-0.12.1.6'

 System stats:
 ghc-6.12.3
 template-haskell-2.4.0.1
 wx-0.12.1.6

 Regards,

 Alex

 [1] Example:

 -- Test.hs --

 {-# LANGUAGE TemplateHaskell #-}
 module Test2 where

 import Language.Haskell.TH
 import qualified Graphics.UI.WX as WX

 foo :: Q [Dec]
 foo = do
  info - reify ''WX.Color
  runIO $ print info
  return []

 -- Main.hs --

 {-# LANGUAGE TemplateHaskell #-}
 module Main where

 import Test

 $(foo)


 ___
 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] forcing a type constraint on data

2011-01-02 Thread Erik Hesselink
On Sun, Jan 2, 2011 at 01:37, Mathijs Kwik bluescreen...@gmail.com wrote:
 The original package
 http://hackage.haskell.org/packages/archive/reaction-logic/2010.11.17/doc/html/Data-Reactor.html
 has a constructor function (mkReactor) with exactly the constraints
 I'm after. However, the constraint is just on this constructor
 function, not on the data itself.
 All functions I write are inferred as Reactor (State s) c, while the
 use of that constructor ensures that s == c.

The haskell98 way to do this, is to restate the constraints in every
function where you use your data type. So every function that uses a
Reactor m c and needs the fact that it has a MonadState c m, needs
this in its context: MonadState c m = Reactor m c - ...

Using the GADTs language extension, you can create a constructor that
contains the proof that the type contained is a member of a certain
type class. For example:

data HasShow a where
  HasShow :: (Show a) = a - HasShow a

newShow :: HasShow a - String
newShow (HasShow x) = show x

Note that newShow doesn't need a Show a constraint.

Erik

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


Re: [Haskell-cafe] HaXml installation trouble

2011-01-03 Thread Erik Hesselink
This happens because haskel98-1.1.0.0 can't be built with GHC 6.12,
but lacks the proper version constraints to enforce this. If you add
'--constraint=haskell98==1.0.*' to your 'cabal install' command, it
will probably work.

Erik

On Mon, Jan 3, 2011 at 01:08, Matthew Fairtlough
resea...@fairtlough.net wrote:
 Still very new here.  I'm trying to install HaXml and I've updated cabal.  I
 see that a similar issue was posted recently as a bug
 http://hackage.haskell.org/trac/ghc/ticket/4513 but one that's supposedly
 fixed; do I need to wait for something or can this be fixed some other way?
  I think I've posted all necessary version numbers below:

 ~ $ sudo cabal install HaXml-1.20.2 --global
 Resolving dependencies...
 Downloading haskell98-1.1.0.0...
 Configuring haskell98-1.1.0.0...
 Preprocessing library haskell98-1.1.0.0...
 ...info deleted...
 [24 of 30] Compiling Directory        ( Directory.hs, dist/build/Directory.o
 )

 Directory.hs:34:38: Not in scope: `setOwnerReadable'

 Directory.hs:35:38: Not in scope: `setOwnerWritable'

 Directory.hs:36:38: Not in scope: `setOwnerExecutable'

 Directory.hs:37:38: Not in scope: `setOwnerSearchable'

 Directory.hs:38:57: Not in scope: `emptyPermissions'
 cabal: Error: some packages failed to install:
 HaXml-1.20.2 depends on haskell98-1.1.0.0 which failed to install.
 haskell98-1.1.0.0 failed during the building phase. The exception was:
 ExitFailure 1
 polyparse-1.4 depends on haskell98-1.1.0.0 which failed to install.

 ~ $ cabal --version
 cabal-install version 0.8.2
 using version 1.8.0.6 of the Cabal library

 ~ $ ghc --version
 The Glorious Glasgow Haskell Compilation System, version 6.12.3

 ~ $ sw_vers
 ProductName:    Mac OS X
 ProductVersion:    10.6.5
 BuildVersion:    10H574



 ___
 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: Applicative = Monad: Call for consensus

2011-01-24 Thread Erik Hesselink
On Tue, Jan 25, 2011 at 05:13, Ryan Ingram ryani.s...@gmail.com wrote:
 On Fri, Jan 21, 2011 at 7:58 PM, Casey Hawthorne cas...@istar.ca wrote:
 uj supplied this:

 About the discussion
 putStrLn (readLn + (5 :: Int))..

 I'll write it as the following line,

 importing Control.Applicative
 main = (+) readLn (return 3)

 They look almost exactly same in my eyes..

 You're missing some bits.

 main = print = liftM2 (+) readLn (return 3)

 Which I assert looks like more line noise than some perl programs I've read. 
 :)

Why not just:

main = print . (+3) = readLn

This reads almost as well as a function composition f . g . h, I think.

Erik

P.S. I wanted to say you could also write it left-to-right using 
from Control.Arrow, but that need parentheses:

main = readLn = ((+3)  print)

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


Re: [Haskell-cafe] Convert a function to a string of operators?

2011-03-11 Thread Erik Hesselink
On Thu, Mar 10, 2011 at 13:34, Lyndon Maydwell maydw...@gmail.com wrote:
 Will methods explained here work for boolean expressions?

 The convenience of defining using specialised datatypes for
 serialising numeric operations comes from Num being a typeclass. This
 is not the case for Bool:

 Prelude :info Num
 class (Eq a, Show a) = Num a where
  (+) :: a - a - a
   ... -- Defined in GHC.Num

 Prelude :info Bool
 data Bool = False | True        -- Defined in GHC.Bool

If you want something like this for Bool (and other standard data
types) have a look at the Awesome Prelude [1]. It is an implementation
of the prelude where each data type is a type class.

Erik

[1] http://tom.lokhorst.eu/2010/02/awesomeprelude-presentation-video

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


Re: [Haskell-cafe] Data.Time.Calendar.Day does not seem to have an instance for Read

2011-03-17 Thread Erik Hesselink
On Thu, Mar 17, 2011 at 07:30, C K Kashyap ckkash...@gmail.com wrote:
 On Thu, Mar 17, 2011 at 12:30 AM, C K Kashyap ckkash...@gmail.com wrote:
  Hi,
  I was wondering if this is a defect -
  Prelude import Data.Time.Calendar
  Prelude Data.Time.Calendar read 2011-10-10 :: Day
  interactive:1:1:
      No instance for (Read Day)
        arising from a use of `read'
      Possible fix: add an instance declaration for (Read Day)
      In the expression: read 2011-10-10 :: Day
      In an equation for `it': it = read 2011-10-10 :: Day
  Prelude Data.Time.Calendar
 

 I see the same problem with GHC 7.0.2, time-1.2.0.3.

 Does it work if you use it in a Haskell source file, instead of GHCi?

 Nope, even compiling with ghc causes the error.

So then it's not a bug. The instance is defined in
Data.Time.Format.Parse, and Data.Time.Calendar doesn't import that
module.

This, however is a bug, I think:

Prelude import Data.Time
Prelude Data.Time read 2011-10-10 :: Day

... no instance for (Read Day) ...

Prelude :m +Data.Time
Prelude Data.Time read 2011-10-10 :: Day
2011-10-10


Erik

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


Re: [Haskell-cafe] GHC 7/Cabal request for help

2011-03-24 Thread Erik Hesselink
I've just tested this, and with GHC 7, cabal chooses QuickCheck 2.4,
whereas with GHC 6.12, it chooses 2.1. If I specify that 6.12 should
choose 2.4 as well, I get the same issue there. This is to be
expected, because I don't see the CPP checks you mentioned in
Test/QuickCheck/Instances.hs in testpack-2.0.1. Perhaps you haven't
released a version with those checks yet?

Erik

On Thu, Mar 24, 2011 at 14:18, John Goerzen jgoer...@complete.org wrote:
 Hi folks,

 I don't have a GHC 7 environment running yet (it's on my list...) but I
 received a bug report pointing me at this build failure:

 http://hackage.haskell.org/packages/archive/testpack/2.0.1/logs/failure/ghc-7.0

 Among other things, this noted:

 Dependency QuickCheck =2.1.0.3: using QuickCheck-2.4.0.1

 and the errors were:

 [1 of 3] Compiling Test.QuickCheck.Instances (
 src/Test/QuickCheck/Instances.hs, dist/build/Test/QuickCheck/Instances.o )

 src/Test/QuickCheck/Instances.hs:39:10:
    Duplicate instance declarations:
      instance Arbitrary Word8
        -- Defined at src/Test/QuickCheck/Instances.hs:39:10-24
      instance Arbitrary Word8 -- Defined in Test.QuickCheck.Arbitrary

 src/Test/QuickCheck/Instances.hs:42:10:
    Duplicate instance declarations:
      instance CoArbitrary Word8
        -- Defined at src/Test/QuickCheck/Instances.hs:42:10-26
      instance CoArbitrary Word8 -- Defined in Test.QuickCheck.Arbitrary

 Now, that's fairly standard, and in fact, in my code, is wrapped with:

 #if MIN_VERSION_QuickCheck(2,3,0)
    -- we have Word8 instances here
 #else
 instance Arbitrary Word8 where
    arbitrary = sized $ \n - choose (0, min (fromIntegral n) maxBound)

 instance CoArbitrary Word8 where
    coarbitrary n = variant (if n = 0 then 2 * x else 2 * x + 1)
                where x = abs . fromIntegral $ n
 #endif

 And that code has been working to support modern QuickCheck versions for
 some time.

 It would appear that something in Cabal, GHC 7, or QuickCheck is breaking
 this check.

 Ideas?

 -- 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] impoosible dependencies

2011-04-21 Thread Erik Hesselink
On Thu, Apr 21, 2011 at 19:25, Rogan Creswick cresw...@gmail.com wrote:
 It is safe to do this.  You will probably need to specify the full
 version, since despite being included in the latest haskell platform,
 cabal-install-0.10.x is in the list of things that cabal won't install
 automatically. (in the same way that it selects versions of parsec...)

It doesn't seem to do this anymore for parsec. The preferred-versions
now look like this:

base  4
cabal-install  0.10
network  2.2.3 || = 2.2.4

Or am I looking at the wrong thing?

Erik

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


Re: [Haskell-cafe] Server hosting

2011-05-07 Thread Erik Hesselink
On Sat, May 7, 2011 at 12:38, Andrew Coppin andrewcop...@btinternet.com wrote:
 On 07/05/2011 09:10 AM, Gregory Collins wrote:

 Linode. Can't recommend them highly enough.

 If Linode is really the cheapest that the Internet has to offer, I'm going
 to need to find a job that pays /significantly/ more money...

 (I'm also not sure whether being billed in USD is possibly a bad idea. Banks
 have a habit of charging you currency conversion fees for that. Then again,
 I haven't found many companies that list prices in GBP.)

There's definitely cheaper services. We rent dedicated servers at
leaseweb (leaseweb.com, they bill in euros), and they have them
starting at €33. They also have virtual servers starting at €9. Their
deals, especially with dedicated servers, fluctuate quite a bit, so it
can pay off to check back if you can't find something good.

Erik

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


Re: [Haskell-cafe] Locking, unsafePerformIO and bolt-on thread safety.

2011-05-10 Thread Erik Hesselink
My first thought was to create all of the lookup table lazily, and
create a pure top level binding for it. Something like:

lookupTable :: [Int]
lookupTable = map (\x - unsafePerformIO (create_lookup_table x) `seq` x) [1..]

Then on a calculation you would index into this list and pass the
result as the last argument to perform_math. However, I'm not sure how
evaluation of thunks works with multiple threads; it might be possible
that this will occasionally execute create_lookup_table twice. I found
this paper [1] which suggests (in 3.5) that it does indeed, and they
suggest a primitive (justOnce :: a - a) to prevent it. So I guess
this won't work, unless things have changed since 2005.

Erik

[1] 
http://research.microsoft.com/en-us/um/people/simonpj/papers/parallel/multiproc.pdf

On Tue, May 10, 2011 at 02:45, Jason Dusek jason.du...@gmail.com wrote:
  A friend is making bindings to a C library that offers some
  fast math operations. The normal way to use the library is
  like this:

    int a = ...; int b = ...; int c = ...; int d = ...;
    int x                    =  ...;
    int m, n;
    create_lookup_table(x);
    m                        =  perform_math(a, b, x);
    n                        =  perform_math(c, d, x);

  We see that the lookup table for x must be created before we
  can perform math in the field/ring/what-have-you defined by x.
  Once we have created the table, though, we're done.

  My friend would like to create a pure interface to this
  library. One thought was to write an interface to perform_math
  that checked if the table was created, created it if not, and
  did all this while locking an MVar so that no other instance
  could be called at the same time, trashing the table. Doing
  this behind unsafePerformIO would seem to be the ticket.

  We end up with an implementation like this:

    module FastMath where

    import Control.Concurrent
    import Foreign
    import Foreign.C


    foreign import ccall create_lookup_table :: CInt - IO ()
    foreign import ccall perform_math :: CInt - CInt - CInt - IO CInt

    masterLock               =  unsafePeformIO (newMVar [CInt])

    safe_perform_math a b x  =  do
      list                  -  takeMVar masterLock
      toPut                 -  if not (x `elem` list)
                                  then do create_lookup_table x
                                          return (x:list)
                                  else    return list
      result                -  perform_math a b x
      putMVar masterLock toPut
      return result

    performMath a b x = unsafePerformIO (safe_perform_math a b x)

  This does not compile but I think it gets the point across. Is
  this approach safe? The unsafePerformIO in conjunction with
  locking has me worried.

 --
 Jason Dusek
 ()  ascii ribbon campaign - against html e-mail
 /\  www.asciiribbon.org   - against proprietary attachments

 ___
 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] Status of Haskell + Mac + GUIs graphics

2011-05-20 Thread Erik Hesselink
On Fri, May 20, 2011 at 20:39, Gregory Crosswhite
gcr...@phys.washington.edu wrote:
 On 5/20/11 8:35 AM, Jeremy O'Donoghue wrote:

 I would like to suggest, quite seriously, that the Haskell community try
 to come to a consensus about supporting a single Haskell GUI, with a view to
 distribution in the HP. Obviously my vote is for wxHaskell, but I'm quite
 prepared to loose the vote. Reason is that I think we need to concentrate
 some effort on getting one GUI binding to 'production' status, and I don't
 believe that on the current basis we will ever do this. From my perspective,
 only GtkHS and wxHaskell look like serious candidates with at least some
 history and maturity behind them.

 If you are going to rule out Qt, then the only good cross-platform option
 remaining is wx since Gtk is not fully native on OSX but instead uses X11
 which results in an inferior user experience, and it would be a bad idea to
 have that be the standard that everyone associates with applications written
 in Haskell.

Note that it is supposed to be possible to build gtk2hs with gtk+osx,
which will not use X11 but use the native OS X GUI. I've not been able
to get this to work, but it's been a while since I tried. The Haskell
wiki mentions it doesn't support Glade, but does support Cairo. If
this were to work, gtk2hs would be a serious option as well.

Erik

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


Re: [Haskell-cafe] SIGSEGV in yieldCapability ()

2011-05-23 Thread Erik Hesselink
On Sun, May 22, 2011 at 15:03, Johannes Waldmann
waldm...@imn.htwk-leipzig.de wrote:
  I think you should file a bug report with a test case
 on GHC.

 I am willing to work on this, but I thought I'd go fishing for some
 advice first. My program uses: forkIO, STM, and FFI.

I've seen something like this, using only forkIO, so I'd start looking
there. I was trying to create a reduced test case, but haven't
reported a bug yet.

 I think that heap exhausted sometimes gets reported
 as evacuate: strange closure,
 (cf.  http://hackage.haskell.org/trac/ghc/ticket/5085 )
 and yieldCapability() might be another instance.

Thank you, we just had this message, and I had no idea what it was.

Erik

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


Re: [Haskell-cafe] Type Constraints on Data Constructors

2011-06-09 Thread Erik Hesselink
On Thu, Jun 9, 2011 at 09:46, DavidA polyom...@f2s.com wrote:
 I think that's exactly what the original poster is complaining about. As a 
 real-
 life example, consider
 data Graph a = Ord a = G [a] [[a]]

 My intention is that whenever I have a Graph a, I want to be able to use the 
 Ord
 instance on a.

 So suppose I now define
 automorphisms :: (Ord a) = Graph a - [Permutation a]

 On the basis of the don't repeat yourself principle, it seems redundant to
 have to specify the (Ord a) context here, since I already specified it in the
 data constructor for Graph a.

 So this is a proposal for a change to the language: don't require a context 
 on a
 function if it is already implied by a context on a data type.

You can do this using GADTs. Like this:

data Graph a where
  G :: Ord a = [a] - [[a]] - Graph a

Now functions that pattern match on the 'G' constructor automatically
have the Ord instance in scope, so it is no longer needed in the
signature.

Erik

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


Re: [Haskell-cafe] Replacing stdin from within Haskell

2011-06-09 Thread Erik Hesselink
On Thu, Jun 9, 2011 at 13:40, Neil Davies semanticphilosop...@gmail.com wrote:
 Anyone out there got an elegant solution to being able to fork a haskell 
 thread and replace its 'stdin' ?

If you don't mind being tied to GHC you can use hDuplicateTo from
GHC.IO.Handle [1]. You can also use dupTo from the unix package [2],
but that ties you to unix-like platforms instead.

Erik

[1] 
http://hackage.haskell.org/packages/archive/base/latest/doc/html/GHC-IO-Handle.html#v:hDuplicateTo
[2] 
http://hackage.haskell.org/packages/archive/unix/latest/doc/html/System-Posix-IO.html#v:dupTo

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


Re: [Haskell-cafe] Replacing stdin from within Haskell

2011-06-09 Thread Erik Hesselink
On Thu, Jun 9, 2011 at 16:40, Donn Cave d...@avvanta.com wrote:
 Quoth Erik Hesselink hessel...@gmail.com,
 On Thu, Jun 9, 2011 at 13:40, Neil Davies semanticphilosop...@gmail.com 
 wrote:
 Anyone out there got an elegant solution to being able to fork a haskell 
 thread and replace its 'stdin' ?

 If you don't mind being tied to GHC you can use hDuplicateTo from
 GHC.IO.Handle [1]. You can also use dupTo from the unix package [2],
 but that ties you to unix-like platforms instead.

 From reading about it, I would expect hDuplicate to to close and
 replace the input file descriptor for _all_ threads.

 Processes are of course the elegant way to separate effects like this.

Ah yes, you are right. I've done this before, but that was after a
double fork using 'forkProcess'.

Erik

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


Re: [Haskell-cafe] Map Monoid instance (was commutative monoid?)

2011-06-25 Thread Erik Hesselink
On Sat, Jun 25, 2011 at 19:07, Evan Laforge qdun...@gmail.com wrote:
 On Sat, Jun 25, 2011 at 9:00 AM, Jens Blanck jens.bla...@gmail.com wrote:
  So there's a range of possible Monoid instances for each type,

 More for some types than for others. For Maybe there are three:

  * always take the first/left value;
  * always take the last/right value;
  * or, use a semigroup operation defined on the values.

Brent Yorgey recently blogged about a fourth instance [1] which also
uses the semigroup operation on the values, but treats Nothing as
failure, returning Nothing.

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] Patterns for processing large but finite streams

2011-07-01 Thread Erik Hesselink
This sound exactly like what attribute grammars, like the system
developed at Utrecht University [1], are useful for.

Erik

[1] http://www.cs.uu.nl/wiki/HUT/AttributeGrammarSystem

On Fri, Jul 1, 2011 at 10:54, Eugene Kirpichov ekirpic...@gmail.com wrote:
 Alexey, your definition of mean does not look like liftS2 (/) sum
 length - you have to manually fuse these computations.

 I'm asking for a formalism that does this fusion automatically (and
 guaranteedly).

 2011/7/1 Alexey Khudyakov alexey.sklad...@gmail.com:
 On Fri, Jul 1, 2011 at 12:21 PM, Eugene Kirpichov ekirpic...@gmail.com 
 wrote:
 I meant the average of the whole list - given a sumS and lengthS (S
 for Stream), write meanS as something like liftS2 (/) sumS lengthS.

 Or is that possible with lazy lists too?

 Sure you can. Sum, length and mean could be calculated as left
 fold. If you need to calculate more that one statistic at time you
 can combine accumulators

 sum = foldl (+) 0
 length = foldl (\n _ - n+1) 0
 data Mean Double Int
 mean = foldl (\(Mean m n) x - Mean (m + (x - m) / fromIntegral (n+1)) 
 (n+1)) (Mean 0 0)

 AFAIU iteratees basically use same technique.




 --
 Eugene Kirpichov
 Principal Engineer, Mirantis Inc. http://www.mirantis.com/
 Editor, http://fprog.ru/

 ___
 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.Time

2011-07-02 Thread Erik Hesselink
On Saturday, July 2, 2011, Joe Healy j...@omc-international.com.au wrote:
 One of the points I found non obvious were the fact that local time is
 just that. There is no knowledge of the actual timezone in the data
 type. If you wish to store that, it needs to be stored alongside.

Isn't that what ZonedTime [1] is for?

[1] 
http://hackage.haskell.org/packages/archive/time/1.1.4/doc/html/Data-Time-LocalTime.html

Erik

 I've attached my test program in the hope that it will be useful for
 someone (or if it is bad, get some help). Is there somewhere/way to
 contribute some examples or documentation?  I feel the time home page
 (http://semantic.org/TimeLib/) makes the library feel more experimental
 than it really is.

 Cheers,

 Joe


 On Mon, 2011-06-27 at 07:37 -0700, bri...@aracnet.com wrote:
 On Mon, 27 Jun 2011 11:15:28 +0300
 Yitzchak Gale g...@sefer.org wrote:

 
  The biggest shortcoming, in my opinion, is that the documentation
  assumes that the reader is very familiar with the Haskell type
  system, and with viewing type signatures and instance lists as an
  integral and central part of the documentation.
 
  In particular, Haskell's standard numeric type classes and the
  conversion functions between them play a central role in the API
  of Data.Time. But you wouldn't realize that unless you have read
  the type signatures and instance lists in the Haddocks very
  carefully, and have thought about it for a while.

 This is exactly right.

 
  Another problem, as Malcolm pointed out, is that because of the
  sheer size of the library, a quick-start guide for the common
  cases would be extremely helpful for newcomers.

 That would be very, very helpful.  I had a few working examples things were 
 much better.  Finding a starting place, any starting place, proved to be 
 quite elusive.  Also the fact that asking for the current time traps you in 
 IO hell, doesn't help, although it's clear that it should be that way.

 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] custom SQL-to-Haskell type conversion in HDBC

2011-08-19 Thread Erik Hesselink
On Fri, Aug 19, 2011 at 07:23, Henry House hajho...@hajhouse.org wrote:
 Does there exist any sample code or other resources on writing a custom
 SQL-to-Haskell datatype converter instance for use with HDBC that would be
 accessible to someone just starting with Haskell? The reason I need this is
 because of this problem (using PostgreSQL):

 Prelude Database.HDBC.PostgreSQL Database.HDBC res - (quickQuery db select 
 1::numeric(5,4); [])
 Prelude Database.HDBC.PostgreSQL Database.HDBC res
 [[SqlRational (1 % 1)]]
 Prelude Database.HDBC.PostgreSQL Database.HDBC res - (quickQuery db select 
 1::numeric(5,0); [])
 [[SqlRational (1 % 1)]]

 where db is a database connection. The SQL values 1::numeric(5,4) and
 1::numeric(5,0) are supposed to be fixed-precision numbers having 4 and zero
 significant decimal figures after the decimal point, respectively. Both are
 offered by HDBC as the same SqlValue, SqlRational (1 % 1) but they are not
 really the same at all. The precision information has been lost. The native
 outputs of PostgreSQL, before HDBC's type conversion, are 1. and 1 for
 'select 1::numeric(5,4);' and 'select 1::numeric(5,0);', respectively.

Do you really need the precision info about the column, or do you just
need the values at the right precision? Because you get the last thing
already:

Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio
Control.Monad (fromSql . head . head) `liftM` (quickQuery db select
1.231 ::numeric(5,0); []) :: IO Rational
1 % 1
Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio
Control.Monad (fromSql . head . head) `liftM` (quickQuery db select
1.231 ::numeric(5,4); []) :: IO Rational
1231 % 1000

If you need the precision information, perhaps 'describeResult' will
give you what you need. I've never used it, but it looks like it
might.

Erik

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


Re: [Haskell-cafe] Problem with types

2011-08-19 Thread Erik Hesselink
On Fri, Aug 19, 2011 at 14:06, Anupam Jain ajn...@gmail.com wrote:
 Hi all,
 Suppose I have a compound data type -
 data M o = M (String,o)
 Now, I can define a function that works for ALL M irrespective of o. For
 example -
 f :: M o - M o
 f (M (s,o)) = M (s++!, o)
 I can also use this function in an expression, applying it to different
 types without problem -
 p = (m1',m2') where
   m1 = M (1, ())
   m2 = M (2, True)
   m1' = f m1
   m2' = f m2
 Main* p
 (M (1!,()),M (2!,True))
 However, if I try to parameterise over the function 'f' it does not work!  -
 p f = (m1',m2') where
   m1 = M (1, ())
   m2 = M (2, True)
   m1' = f m1
   m2' = f m2
 It doesn't even typecheck, producing the error - Couldn't match expected
 type 'Bool' with actual type '()'
 Is there a particular reason for this? How can I define a function like 'p'
 within Haskell?

If you write down the type for 'p', you get something like this:

p :: (forall a. M a - M a) - (M b, M b)

That is, the type variable 'a' isn't top level, but is forall'ed in
the function you pass. This is called a rank 2 type, and it cannot be
inferred automatically by GHC. You have to specify it yourself, and
turn on the Rank2Types or RankNTypes extension.

Erik

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


Re: [Haskell-cafe] custom SQL-to-Haskell type conversion in HDBC

2011-08-19 Thread Erik Hesselink
On Fri, Aug 19, 2011 at 16:09, Henry House hajho...@hajhouse.org wrote:
 On Friday, 19 August 2011, Erik Hesselink wrote:
 Do you really need the precision info about the column, or do you just
 need the values at the right precision? Because you get the last thing
 already:

 Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio
 Control.Monad (fromSql . head . head) `liftM` (quickQuery db select
 1.231 ::numeric(5,0); []) :: IO Rational
 1 % 1
 Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio
 Control.Monad (fromSql . head . head) `liftM` (quickQuery db select
 1.231 ::numeric(5,4); []) :: IO Rational
 1231 % 1000

 I'm not sure I understand the distinction --- to my way of thinking,
 getting the value at the right precision means getting the correct
 number of significant decimal digits, which both your example and mine
 fail to provide.

 Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio Control.Monad
 (fromSql . head . head) `liftM`
   (quickQuery db select 1.231 ::numeric(10,4); []) :: IO Rational
 -- gives 1231 % 1000 == 1.231 in decimal notation
 Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio Control.Monad
 (fromSql . head . head) `liftM`
   (quickQuery db select 1.231 ::numeric(10,8); []) :: IO Rational
 -- still gives 1231 % 1000 but should be 1.2131 in decimal notation
 -- or 1231000 % 100 in rational notation

The % notation is a rational, so 'infinite' precision. So '1 % 1' and
'1000 % 1000' are exactly the same, semantically. It's like fractions
instead of decimal digits.

Why exactly do you need the precision information?

Erik

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


Re: [Haskell-cafe] custom SQL-to-Haskell type conversion in HDBC

2011-08-19 Thread Erik Hesselink
On Fri, Aug 19, 2011 at 16:53, Henry House hajho...@hajhouse.org wrote:
 On Friday, 19 August 2011, Erik Hesselink wrote:
 Why exactly do you need the precision information?

 Empirical measurements (e.g., sizes of some fields in hectares) are
 precise only to a certain level of measurement error. Thus, the area
 measurements 1 ha and 1.000 ha are not equivalent or interchangeable.
 Database engines recognize this fact by providing different data types
 for rational numbers and fixed-precision decimal numbers.

 The bottom line for me is that the conversion of a fixed-precision
 decimal number as a rational is both throwing away information (the
 precision) as well as introducing bogus information (the notion that the
 result value has greater --- i.e., infinite --- precision that was in
 fact intended when that value was stored).

Note that PostgreSQL also doesn't work with decimals as precision:

postgres=# select 1::decimal(4,2) * 1::decimal(4,2);
?column?
--
   1.
(1 row)

That should be 1.00 instead if you want the precision correctly represented.

Perhaps a solution would be to not treat the database precision as
your primary source of information, but represent that in Haskell
using some data type that correctly propagates precision information,
and marshall your database data to and from that. This means some
duplication of information (precision in both database and Haskell)
but you do the same with NULL and Maybe, etc. I guess that's inherent
to (the way HDBC does) database access.

Erik

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


Re: [Haskell-cafe] custom SQL-to-Haskell type conversion in HDBC

2011-08-20 Thread Erik Hesselink
On Friday, August 19, 2011, Brandon Allbery allber...@gmail.com wrote:
 On Fri, Aug 19, 2011 at 11:45, Erik Hesselink hessel...@gmail.com wrote:

 Note that PostgreSQL also doesn't work with decimals as precision:

 postgres=# select 1::decimal(4,2) * 1::decimal(4,2);
 ?column?
 --
   1.
 (1 row)

 That should be 1.00 instead if you want the precision correctly
represented.

 Er?  Last I checked, that was exactly how precision worked over
multiplication; otherwise you are incorrectly discarding precision present
in the original values.  Unless you're assuming the OP actually wants an
incorrect flat precision model

This is the way I was taught to do it in physics. See also
http://en.m.wikipedia.org/wiki/Significance_arithmetic

Erik


 --
 brandon s allbery  allber...@gmail.com
 wandering unix systems administrator (available) (412)
475-9364 tel:%28412%29%20475-9364 vm/sms


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


Re: [Haskell-cafe] Is there any way to parametrize a value update using record syntax?

2011-09-06 Thread Erik Hesselink
2011/9/6 Poprádi Árpád popradi_ar...@freemail.hu:
 i have a record with a lot of items used in a state monad.

 data BigData = BigData {
                   data1 :: X
                 , data2 :: X
                -- and so on
                }

 updateData1 :: X - MonadicEnv()
 updateData1 d = do; env - get; put env {data1 = d}

 updateData2 :: X - MonadicEnv()
 updateData2 d = do; env - get; put env {data2 = d}

 But it's ugly. Always the same, only the record selector has another
 name.
 Is it possible to generalize it?

You can use the fclabels package [1] for this. It makes record labels
first class, and also provides functions to update parts of a record
in the state monad [2]. You would be able to write something like:

updateData1 = puts data1 d

It has a function for modifcation as well, which is even uglier with
regular record syntax.

Erik

[1] http://hackage.haskell.org/package/fclabels
[2] 
http://hackage.haskell.org/packages/archive/fclabels/1.0.4/doc/html/Data-Label-PureM.html#v:puts

___
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


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] 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] 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] 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] [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


[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] (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


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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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] 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


  1   2   >