[Haskell-cafe] Win32 API

2009-09-19 Thread Andrew Coppin

Hi guys.

Last time I looked at the Win32 bindings, it covered a few basic file 
I/O things (e.g., special access modes, file permissions, etc.), 
registry editing, and that was about it. Yesterday I took another look, 
and was pleasently surprised to find that GDI is now covered. Suffice it 
to say, yesterday I wrote my very first ever program using the Win32 API 
directly. (Who'd have thought Haskell would be the place to do that?)


This was complicated by a small glitch: Graphics.Win32.Window exposes 
SendMessage() but does not expose PostMessage(). Kind of an important 
difference there. Fortunately, it's not actually especially hard to fix 
this deficiency. (Basically few the source code for the module, copy and 
paste the line for SendMessage(), and edit it to say PostMessage(). The 
type signature just happens to be identical.) Is there a reason why this 
is missing to start with? What other functions are missing? (I didn't 
see PostQuitMessage() anywhere...)


Still, 85 lines of code to make a working, native-looking Windows 
program isn't too shabby, really... (Not that any sane person writes 
nontrivial programs directly like this of course.)


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


[Haskell-cafe] Why the stack overflow?

2009-09-19 Thread staafmeister


Hi haskell-cafe,

Why does rlist 10 [] gives stack overflow in ghci?

rlist 0 l = return l
rlist n l = do {x - randomRIO (1,maxBound::Int); let nl = x:l in nl `seq`
rlist (n-1) nl}

I first uses replicateM then foldM and finally an explicit function. But
they give all stack overflow
I don't know why 10 is not absurd and it is tail recursive. Or is it
not, due to the monad structure?

greetings
Gerben

-- 
View this message in context: 
http://www.nabble.com/Why-the-stack-overflow--tp25520431p25520431.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] Why the stack overflow?

2009-09-19 Thread Daniel Fischer
Am Samstag 19 September 2009 12:37:41 schrieb staafmeister:
 Hi haskell-cafe,

 Why does rlist 10 [] gives stack overflow in ghci?

 rlist 0 l = return l
 rlist n l = do {x - randomRIO (1,maxBound::Int); let nl = x:l in nl `seq`
 rlist (n-1) nl}

 I first uses replicateM then foldM and finally an explicit function. But
 they give all stack overflow
 I don't know why 10 is not absurd and it is tail recursive. Or is it
 not, due to the monad structure?

Prelude System.Random :set -XBangPatterns
Prelude System.Random let rlist2 0 l = return l; rlist2 n l = do { !x - 
randomRIO 
(1,maxBound :: Int); let {nl = x:l}; nl `seq` rlist2 (n-1) nl }
Prelude System.Random rlist2 10 [] = \l - print (take 3 l)  print (last l)
[800589677,541186119,1521221143]
1279766979
Prelude System.Random rlist2 1000 [] = \l - print (take 3 l)  print (last 
l)
[655069099,324945664,2137996923]
1108985638
Prelude System.Random rlist2 1 [] = \l - print (take 3 l)  print 
(last l)
[286279491,63955,2118785404]
315689721
Prelude System.Random rlist2 10 [] = \l - print (take 3 l)  print 
(last l)
[862262999,947331403,790576391]
1250271938
Prelude System.Random rlist2 100 [] = \l - print (take 3 l)  print 
(last l)
[681201080,627349875,484483111]
1048225698
Prelude System.Random rlist2 1000 [] = \l - print (take 3 l)  print 
(last l)
[1247387053,690485134,1924757191]
1637122415

The problem is that randomRIO doesn't evaluate its result, so you build a long 
chain of 
calls to randomR, which isn't evaluated until the count reaches 0, hence the 
stack 
overflow. Forcing x prevents the long chain from being built.

But better don't use randomRIO, make it a pure function with the PRNG as an 
argument.


 greetings
 Gerben

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


Re: [Haskell-cafe] Win32 API

2009-09-19 Thread Duncan Coutts
On Sat, 2009-09-19 at 08:52 +0100, Andrew Coppin wrote:

 This was complicated by a small glitch: Graphics.Win32.Window exposes 
 SendMessage() but does not expose PostMessage(). Kind of an important 
 difference there. Fortunately, it's not actually especially hard to fix 
 this deficiency. (Basically few the source code for the module, copy and 
 paste the line for SendMessage(), and edit it to say PostMessage(). The 
 type signature just happens to be identical.) Is there a reason why this 
 is missing to start with? What other functions are missing? (I didn't 
 see PostQuitMessage() anywhere...)

I doubt there's any reason it was not bound except that it was not
needed by the person who bound the related ones. Send in your patch.

Duncan

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


Re: [Haskell-cafe] Suggested additions to System.FilePath.Posix/Windows

2009-09-19 Thread Duncan Coutts
On Thu, 2009-09-17 at 11:58 +0200, Marcus D. Gabriel wrote:

  -- | 'reduceFilePath' returns a pathname that is reduced to canonical
  -- form equivalent to that of ksh(1), that is, symbolic link names are
  -- treated literally when finding the directory name.  See @cd -L@ of
  -- ksh(1).  Specifically, extraneous separators @(\/\)@, dot
  -- @(\.\)@, and double-dot @(\..\)@ directories are removed.
 
  reduceFilePath :: FilePath - FilePath
  reduceFilePath = joinPath . filePathComponents

So it's like the existing System.Directory.canonicalizePath but it's
pure and it does not do anything with symlinks. On the other hand
because it's pure it can do something with non-local paths.

Is there anything POSIX-specific about this? I don't see it.

Duncan

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


[Haskell-cafe] Re: [Hs-Generics] how to automatically create and install documentations of a package?

2009-09-19 Thread Sean Leather
Hi Daneel,

On Sat, Sep 19, 2009 at 13:58, Daneel Yaitskov wrote:

 Recently I've found wonderful thing cabal can install packages itself! It
 can even install those packages which need for final one. But I'm disturbed
 cabal doesn't create the documentation of a package by default. It manually
 makes runhaskell Setup haddock.

 Who knows?


I believe you can do 'cabal haddock', but I don't know why it doesn't do it
by default.

BTW, the Haskell Café is typically more suitable for questions such as
these. The Generics list is more specifically for generic programming
discussions while the Haskell Café serves a broader audience. I've CC'd
haskell-cafe@ to see if anybody there knows the answer to your question.

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


Re: [Haskell-cafe] Re: [Hs-Generics] how to automatically create and install documentations of a package?

2009-09-19 Thread Gwern Branwen
On Sat, Sep 19, 2009 at 11:59 AM, Sean Leather leat...@cs.uu.nl wrote:
 Hi Daneel,

 On Sat, Sep 19, 2009 at 13:58, Daneel Yaitskov wrote:

 Recently I've found wonderful thing cabal can install packages itself! It
 can even install those packages which need for final one. But I'm disturbed
 cabal doesn't create the documentation of a package by default. It manually
 makes runhaskell Setup haddock.

 Who knows?

 I believe you can do 'cabal haddock', but I don't know why it doesn't do it
 by default.

 BTW, the Haskell Café is typically more suitable for questions such as
 these. The Generics list is more specifically for generic programming
 discussions while the Haskell Café serves a broader audience. I've CC'd
 haskell-cafe@ to see if anybody there knows the answer to your question.

 Regards,
 Sean

If you use cabal-install (as you should!), you can have it build
haddocks by customizing ~/.cabal/config and adding:

documentation: True

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


[Haskell-cafe] Re: Is it safe to use unsafePerformIO here?

2009-09-19 Thread Ben Franksen
Cristiano Paris wrote:
 Daniel Fischer wrote:
 I would separate the reading of headers and bodies, reopening the files
 whose body is needed, for some (maybe compelling) reason he wants to do
 it differently.
 
 Yes, that's the way Haskell forces you to do that as it's the only way
 for you to go safe.

I don't think it has anything to do with Haskell. How would you do this in
C? You'd pass a flag indicating whether to read the whole file or just the
header. You can do the same in Haskell, of course, no lazy IO needed. The
body remains undefined if the flag indicates header only. Even better wrap
the body in a Maybe.

 But, if you know more about your code, you can use
 unsafe(Perform|Interleave)IO to assure the compiler that everything's
 right.

I have a hard time believing this is possible, if you demand that the files
should not stay opened indefinitely. How is the runtime supposed to know
whether to close the file or not? What you /can/ do is use unsafePerformIO
to lazily re-open, read the body, and close the file, as soon as the body
gets demanded. However, this is ugly and not advised.

Cheers
Ben

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


[Haskell-cafe] Haskell Weekly News: Issue 131 - September 19, 2009

2009-09-19 Thread Joe Fredette
Hopefully the line endings come out okay this week, I did a test  
before sending it to the list, please let me know if you notice  
anything awry. Just put a [HWN] in the subject line so my filter's  
will catch it. /metaeditorial


---
Haskell Weekly News
http://sequence.complete.org/hwn/20090918
Issue 131 - September 18, 2009
---
   Welcome to issue 131 of HWN, a newsletter covering developments in  
the

   [1]Haskell community.

   Last week, I received an email from Mark Wotton about his project
   [2]Hubris. I totally forgot to put it in the HWN last week, too busy
   trying to figure out all the tools. So, I thought I'd make it up and
   give him some special editorial status this week. Hubris is a bridge
   between Ruby and Haskell, allowing you to call Haskell from Ruby.  
It's
   very cool, I highly suggest playing with it. Also, I've been  
posting a

   bit about the new HWN tools (dubbed HWN2) on my [3]blog, there is
   also a repo up at [4]patch-tag which will have all the code. If  
there

   is some interest in helping me, I'll try to come up with a TODO
   list/Trac.

Announcements

   hssqlppp, sql parser and type checker, pre-alpha. Jake Wheat
   [5]announced his parser/type checker for SQL. It currently parses a
   subset of PostGreSQL and PL/pgSQL, and can type check some  
statements.


   LambdaINet-0.1.0, Graphical Interaction Net Evaluator for Optimal
   Evaluation. Paul L [6]announced a LambdaINet 0.1.0, available on
   [7]Hackage. LambdaINet implements an interaction net based optimal
   evaluator. With an interactive graphical interface allowing the  
user to

   view and directly manipulate the interaction net.

   arbtt-0.1. Joachim Breitner [8]announced the Automatic Rule-Based  
Time

   Tracking tool on hackage. he has an introduction available [9]here.

   A statistics library. Bryan O'Sullivan [10]announced the  
imaginatively

   named [11]statistics library. Which supports common discrete and
   continuous probability distributions, Kernel density estimation,
   Auto-correlation analysis, Functions over sample data, Quantile
   estimation, and Re-sampling techniques.

   CFP: JSC Special Issue on Automated Verification and Specification  
of
   Web Systems. [12]A Special Issue of the Journal of symbolic  
computation

   was announced. This issue is related to the topics of the Automated
   Specification and Verification of Web Systems Workshop (WWV'09).  
Read

   the announcement for more details.

   Haskeline 0.6.2. Judah Jacobson [13]announced the release of  
Haskeline
   0.6.2, available [14]here. Improvements over the last version  
include,
   new emacs and vi bindings, a new preference to remove repeated  
history

   entries, recognition of page-up and page-down keys, and more.

   PEPM'10 - Last CFP (Submission: 6 Oct 09, Notification: 29 Oct 09).
   Janis Voigtlaender [15]announced the Last Call for Papers for  
PEPM'10,

   see the announcement for more details.

   Videos of HIW 2009. Malcolm Wallace [16]announced videos of all the
   presentations/discussions at the recent Haskell Implementers  
Workshop

   2009, in Edinburgh, are now [17]online. The program of talks is
   available [18]here.

   Unification in a Commutative Monoid (cmu 1.1) and a new release of
   Abelian group unification and matching (agum 2.2). John D. Ramsdell
   [19]announced cmu 1.1, which provides unification in a commutative
   monoid, also know as ACU-unification. The core computation finds the
   minimal non-zero solutions to homogeneous linear Diophantine  
equations.

   The linear equation solver has been place in a separate module so it
   can be used for other applications. He also announced agum 2.2,  
which

   provides unification and matching in an Abelian group, also know as
   AG-unification and matching.

   graphviz-2999.5.1.0. Ivan Lazar Miljenovic [20]announced a bug-fix
   release of the GraphViz package, no major API changes occurred.

   levmar-0.2, bindings-levmar-0.1.1. Bas van Dijk and Roel van Dijk
   announced [21]new [22]versions of the levmar and bindings-levmar
   packages. New features include automatic calculation of the Jacobian
   via Conal Elliot's automatic differentiation from his vector-space
   library.

   CmdArgs - easy command line argument processing. Neil Mitchell
   [23]announced CmdArgs 0.1. CmdArgs is a library for parsing
   command-line arguments. It offers several improvements over GetOpts,
   namely that the Command Line Argument Processors are shorter and
   CmdArgs can support multiple-mode command lines such as those  
found in

   darcs, cabal, hpc, etc.

   OpenGL 2.4.0.1. Sven Panne [24]announced a new version of the OpenGL
   package, this version fixes a bug that didn't make it into the  
previous

   release.

   OpenGLRaw 1.1.0.0. Sven Panne [25]announced a new version of the
 

Re: [Haskell-cafe] Why the stack overflow?

2009-09-19 Thread Derek Elkins
On Sat, Sep 19, 2009 at 6:54 AM, Daniel Fischer
daniel.is.fisc...@web.de wrote:
 Am Samstag 19 September 2009 12:37:41 schrieb staafmeister:
 Hi haskell-cafe,

 Why does rlist 10 [] gives stack overflow in ghci?

 rlist 0 l = return l
 rlist n l = do {x - randomRIO (1,maxBound::Int); let nl = x:l in nl `seq`
 rlist (n-1) nl}

 I first uses replicateM then foldM and finally an explicit function. But
 they give all stack overflow
 I don't know why 10 is not absurd and it is tail recursive. Or is it
 not, due to the monad structure?

 Prelude System.Random :set -XBangPatterns
 Prelude System.Random let rlist2 0 l = return l; rlist2 n l = do { !x - 
 randomRIO
 (1,maxBound :: Int); let {nl = x:l}; nl `seq` rlist2 (n-1) nl }
 Prelude System.Random rlist2 10 [] = \l - print (take 3 l)  print (last 
 l)
 [800589677,541186119,1521221143]
 1279766979
 Prelude System.Random rlist2 1000 [] = \l - print (take 3 l)  print 
 (last l)
 [655069099,324945664,2137996923]
 1108985638
 Prelude System.Random rlist2 1 [] = \l - print (take 3 l)  print 
 (last l)
 [286279491,63955,2118785404]
 315689721
 Prelude System.Random rlist2 10 [] = \l - print (take 3 l)  print 
 (last l)
 [862262999,947331403,790576391]
 1250271938
 Prelude System.Random rlist2 100 [] = \l - print (take 3 l)  print 
 (last l)
 [681201080,627349875,484483111]
 1048225698
 Prelude System.Random rlist2 1000 [] = \l - print (take 3 l)  print 
 (last l)
 [1247387053,690485134,1924757191]
 1637122415

 The problem is that randomRIO doesn't evaluate its result, so you build a 
 long chain of
 calls to randomR, which isn't evaluated until the count reaches 0, hence the 
 stack
 overflow. Forcing x prevents the long chain from being built.

Incidentally, nl is already in head normal form so seq nl does
nothing.  Leading to:
rlist 0 l = return l
rlist n l = do !x - randomRIO (1, maxBound :: Int); rlist (n-1) (x:l)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Suggested additions to System.FilePath.Posix/Windows

2009-09-19 Thread Brandon S. Allbery KF8NH

On Sep 19, 2009, at 07:45 , Duncan Coutts wrote:

On Thu, 2009-09-17 at 11:58 +0200, Marcus D. Gabriel wrote:
-- | 'reduceFilePath' returns a pathname that is reduced to  
canonical
-- form equivalent to that of ksh(1), that is, symbolic link names  
are
-- treated literally when finding the directory name.  See @cd -L@  
of

-- ksh(1).  Specifically, extraneous separators @(\/\)@, dot
-- @(\.\)@, and double-dot @(\..\)@ directories are removed.


So it's like the existing System.Directory.canonicalizePath but it's
pure and it does not do anything with symlinks. On the other hand
because it's pure it can do something with non-local paths.

Is there anything POSIX-specific about this? I don't see it.


It's making assumptions about the safety of eliding ...  (What does \ 
\machine\share\..\ do?)  On the other hand that's also unsafe on POSIX  
in the presence of symlinks.  In general I consider path cleanup not  
involving validation against the filesystem to be risky.


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




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


Re: [Haskell-cafe] Ambiguous type variable with subclass instance (also: is there a better way to do this?)

2009-09-19 Thread Andy Gimblett


On 17 Sep 2009, at 18:01, Ryan Ingram wrote:


Here's a way that works more closely to your original version:

instance Enumerated a = Target a where
   convert n
   | n = 0  n  numConstrs = Just (constrs !! n)
   | otherwise = Nothing
where
   constrs = constructors
   numConstrs = length constrs


Aha - that's great, and it works without OverlappingInstances (but  
still with FlexibleInstances and UndecidableInstances - should that  
worry me?)


Just making sure constructors is only referenced once is the key, it  
seems.


Thanks!

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


Re: [Haskell-cafe] Ambiguous type variable with subclass instance (also: is there a better way to do this?)

2009-09-19 Thread Daniel Fischer
Am Samstag 19 September 2009 20:55:10 schrieb Andy Gimblett:
 On 17 Sep 2009, at 18:01, Ryan Ingram wrote:
  Here's a way that works more closely to your original version:
 
  instance Enumerated a = Target a where
 convert n
 
 | n = 0  n  numConstrs = Just (constrs !! n)
 | otherwise = Nothing
 
  where
 constrs = constructors
 numConstrs = length constrs

 Aha - that's great, and it works without OverlappingInstances (but
 still with FlexibleInstances and UndecidableInstances - should that
 worry me?)

FlexibleInstances need not worry anybody. They just remove a fairly arbitrary 
restriction 
of Haskell98 for instance declarations.

UndecidableInstances can be dangerous, but there are perfectly safe things 
which reauire 
UndecidableInstances, too.


 Just making sure constructors is only referenced once is the key, it
 seems.

Just making sure that every time it is referenced, it is referenced at the 
correct type.


 Thanks!

 -Andy

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


[Haskell-cafe] Re: Suggested additions to System.FilePath.Posix/Windows

2009-09-19 Thread Simon Marlow

Brandon S. Allbery KF8NH wrote:

On Sep 19, 2009, at 07:45 , Duncan Coutts wrote:

On Thu, 2009-09-17 at 11:58 +0200, Marcus D. Gabriel wrote:

-- | 'reduceFilePath' returns a pathname that is reduced to canonical
-- form equivalent to that of ksh(1), that is, symbolic link names are
-- treated literally when finding the directory name.  See @cd -L@ of
-- ksh(1).  Specifically, extraneous separators @(\/\)@, dot
-- @(\.\)@, and double-dot @(\..\)@ directories are removed.


So it's like the existing System.Directory.canonicalizePath but it's
pure and it does not do anything with symlinks. On the other hand
because it's pure it can do something with non-local paths.

Is there anything POSIX-specific about this? I don't see it.


It's making assumptions about the safety of eliding ...  (What does 
\\machine\share\..\ do?)  On the other hand that's also unsafe on POSIX 
in the presence of symlinks.  In general I consider path cleanup not 
involving validation against the filesystem to be risky.


I agree; this came up before during the design of System.FilePath, and 
it's why the current library doesn't have a way to remove ...  The 
docs should probably explain this point, because it's non-obvious that 
you can't just clean up a path to remove the .. and end up with 
something that means the same thing.


Cheers,
Simon

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


Re: [Haskell-cafe] Ambiguous type variable with subclass instance (also: is there a better way to do this?)

2009-09-19 Thread Edward Kmett
A few issues, you can remove the overlapping instances by using a newtype
wrapper to disambiguate which instance you want.

A little alarm bell goes off in my head whenever I read 'instance Foo a'.

newtype Wrapped a = Wrapped a

instance Target Foo where ...

instance Enumerated a = Target (Wrapped a) where ...

is probably a better idea over all.

As for the use of constructors. your problem is that it is ambiguous which
constructors you want to take the list of.

Try replacing constructors with a local variable. The choice of constructors
then will be fixed by the use of the argument from the Just branch and the
monomorphism restriction constraining you so that the list you take the
length of has the same type.

 instance (Enumerated a) = Target a where
 convert n | n `elem` [0..len-1] = Just $ cons !! n
   | otherwise = Nothing
 where
len = length cons
cons = constructors

You could also do it with some sort of

asListOf :: [a] - a - [a]
asListOf = const

convert n = result where
...
len = length cons
...
cons = constructors `asListOf` result

if relying on the MR makes you feel dirty.

-Edward

On Thu, Sep 17, 2009 at 9:40 AM, Andy Gimblett hask...@gimbo.org.uk wrote:

 Hi all.  This email is in literate Haskell; you should be able to load
 it into ghci and verify what I'm saying (nb: it won't compile without
 alteration: see below).

 I'm trying to do something which may anyway be stupid / not the best
 approach to what I'm trying to achieve; however, it's not working and
 I can't see why not.  So I'm asking for help on two fronts:

 1) Why is this failing?

 2) Maybe more usefully, how should I actually be doing this?  It seems
   an ugly approach; a voice in my head is saying scrap your
   boilerplate, but I've no idea yet if that's actually applicable
   here; should I look at it?

 On with the show...

 I need these for subclass stuff later on...

  {-# LANGUAGE FlexibleInstances #-}
  {-# LANGUAGE OverlappingInstances #-}
  {-# LANGUAGE UndecidableInstances #-}

  module Ambig where

 I wish to define a number of algebraic data types with the ability to
 turn Int values into instances of those types.  So I define a
 typeclass saying this is possible.  I use Maybe so I can encode the
 existence of out-of-range Int values, which will vary from target type
 to target type.

  class Target a where
  convert :: Int - Maybe a

 E.g. here's a type Foo which only wants values between 1 and 10:

  data Foo = Foo Int deriving (Show)
  instance Target Foo where
  convert n | n `elem` [1..10] = Just $ Foo n
| otherwise = Nothing

 (That's a simple example; some are rather more complex.  How to do
 this isn't what I'm asking about, really.)

 So we have, for example:

 *Ambig (convert 1) :: Maybe Foo
 Just (Foo 1)
 *Ambig (convert 11) :: Maybe Foo
 Nothing

 Now, some of those algebraic data type types happen to be
 enumerations; in this case, my idea is to list the constructors, with
 the rule that each constructor's position in the list is the Int which
 gets converted into that constructor.

  class Enumerated a where
  constructors :: [a]

 E.g. here's a type Bar with three constructors:

  data Bar = X | Y | Z deriving (Show)
  instance Enumerated Bar where
  constructors = [X, Y, Z]

 (This is certainly ugly.  Any suggestions?)

 Now we get to the crux.  If a type is an instance of Enumerated, it
 should also be a Target, because we should be able to convert from Int
 just by list lookup.  But we include a bounds check, naturally...

  instance (Enumerated a) = Target a where
  convert n | n `elem` [0..len-1] = Just $ constructors !! n
| otherwise = Nothing
  where len = length constructors

 So I would _hope_ that then, e.g., we'd have:

 *Ambig (convert 0) :: Maybe Bar
 Just X
 *Ambig (convert 1) :: Maybe Bar
 Just Y
 *Ambig (convert 3) :: Maybe Bar
 Nothing

 Sadly, this function doesn't compile, dying with an Ambiguous type
 variable error:

 Ambig.lhs:75:29:
Ambiguous type variable `a' in the constraint:
  `Enumerated a'
arising from a use of `constructors' at Ambig.lhs:74:29-40
Probable fix: add a type signature that fixes these type variable(s)

 If we replace length constructors with 3 (say), it compiles (but
 is useless).  Adding a type signature doesn't help: it's misplaced
 in that context.  If I break it out of the instance declaration so I
 can add one, I still get the same problem:

  convert' :: (Enumerated a, Target a) = Int - Maybe a
  convert' n | n `elem` [0..len-1] = Just $ constructors !! n
 | otherwise = Nothing
  where len = length constructors

 I guess I see roughly what's going on; the question is which
 constructors instance is meant?, right?  In the Just part it's OK,
 because it can be inferred from the function's return type (right?).
 But in the guard we don't have that help, so it could be any
 Enumerated 

Re: [Haskell-cafe] Re: [Hs-Generics] how to automatically create and install documentations of a package?

2009-09-19 Thread Michael Shulman
Gwern Branwen wrote:
 If you use cabal-install (as you should!), you can have it build
 haddocks by customizing ~/.cabal/config and adding:
 
 documentation: True

Is there a way to make it automatically update a single contents page
with links to the documentation of all installed packages?  I have been
doing this manually every time I cabal-install something, by running a
little shell script which looks through all the packages directories for
html directories and .haddock files and compiles them all into a
call to haddock --gen-contents.

Mike

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