Re: [Haskell-cafe] The maximum/minimum asymmetry

2011-09-05 Thread Alexander Dunlap
On 4 September 2011 21:44, Mario Blažević blama...@acanac.net wrote:
    I was recently surprised to discover that the maximum and maximumBy
 functions always return the *last* maximum, while minimum and minimumBy
 return the *first* minimum in the list. The following GHCi session
 demonstrates this:

 $ ghci
 GHCi, version 7.2.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 :module +Data.List Data.Ord
 Prelude Data.List Data.Ord let list = [(1, 'B'), (1, 'A')]
 Prelude Data.List Data.Ord maximumBy (comparing fst) list
 (1,'A')
 Prelude Data.List Data.Ord minimumBy (comparing fst) list
 (1,'B')

    I would normally consider this kind of gratuitous asymmetry a bug, but
 seeing that these functions' implementations have been specified in the
 Haskell 98 Library Report, I guess they are now a permanent feature of the
 language. Can anybody explain the reason for this behaviour?


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


The asymmetry is a result of EQ and LT being treated as equivalent in
both the minBy and maxBy helper functions in the report's definition
of the two functions, which has opposite effects for minimumBy and
maximumBy. Since the documentation doesn't specify a behavior for
equal values, I could guess that it was just an oversight or that it
was considered unimportant. But maybe someone more knowledgeable will
correct me.

Alexander Dunlap

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


Re: [Haskell-cafe] ANNOUNCE: taffybar: an alternative status bar for xmonad

2011-08-15 Thread Alexander Dunlap
On 14 August 2011 14:51, Tristan Ravitch travi...@cs.wisc.edu wrote:
 On Sun, Aug 14, 2011 at 02:45:24PM -0700, Alexander Dunlap wrote:

 I apologize if I'm missing something obvious here, but when I try to
 run taffybar I get

 Launching custom binary /home/alex/.cache/taffybar/taffybar-linux-i386

 taffybar-linux-i386: ConnectionError connectSession:
 DBUS_SESSION_BUS_ADDRESS is missing or invalid.

 Is there some D-BUS configuration that needs to happen before the
 package is usable?

 Sorry, I assumed you would have dbus running already.  If you add a
 line like:

  eval `dbus-launch --auto-syntax`

 early in your ~/.xsession (if logging in via some graphical login
 manager) or ~/.xinitrc (if starting X via startx).  That should work
 for any normal -sh-style or -csh-style shell.

 That command starts DBus and sets the DBUS_SESSION* environment
 variables, and both xmonad and taffybar need to have the same settings
 for that variable, so make sure you execute that command before
 starting either of them.

 I'll add some notes in the documentation about this.


Thanks, that worked! Also, is there a way to change the default color
of text printed by the bar? (I've added span tags with colors to the
different text widget formats, but it would be nice to be able to set
a default - it shows up as a nearly-impossible-to-read dark grey for
me.)

Thanks a lot for the great program!

Alexander

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


Re: [Haskell-cafe] ANNOUNCE: taffybar: an alternative status bar for xmonad

2011-08-14 Thread Alexander Dunlap
On 13 August 2011 08:56, Tristan Ravitch travi...@cs.wisc.edu wrote:
 I've wanted a slightly fancier status bar than xmobar for a while, so
 I finally made one.  It uses gtk2hs and dbus extensively, so if you
 hate either of those things it probably isn't for you.  Being written
 in gtk, though, it can have more graphical widgets.

  http://hackage.haskell.org/package/taffybar

 Current feature highlights:

  * It has a system tray
  * Generic graph widget for things like CPU/memory
  * XMonad log over DBus so it can be restarted independently of xmonad
  * Graphical battery widget

 There is still a lot that I want to add but I figured getting some
 feedback early would be handy.  Documentation is currently at
 http://pages.cs.wisc.edu/~travitch/taffybar until I figure out how to
 appease Hackage (see the System.Taffybar module).


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



I apologize if I'm missing something obvious here, but when I try to
run taffybar I get

Launching custom binary /home/alex/.cache/taffybar/taffybar-linux-i386

taffybar-linux-i386: ConnectionError connectSession:
DBUS_SESSION_BUS_ADDRESS is missing or invalid.

Is there some D-BUS configuration that needs to happen before the
package is usable?

Thanks,
Alex

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


Re: [Haskell-cafe] Small strings

2010-12-05 Thread Alexander Dunlap
On Sun, Dec 5, 2010 at 10:04 PM, Antoine Latter aslat...@gmail.com wrote:
 Hi Haskell,

 I've recently created the 'smallstring' package[1] and put it on
 Hackage. The goal was to create a string-like type with as little
 memory overhead as possible, and to have equality and comparison
 operations be competitive with the native String type. The idea is
 that this type would make ideal keys into data structures like
 Data.Map.

 I've taken pains to make the library portable to other compilers, but
 this isn't really tested, and most of my recent development has been
 on GHC 7. The library is young and likely has places it could be
 improved, so your feedback is welcome.

 The API provided is small - to/fromString along with Eq and Ord instances.

 This isn't meant to be a replacement for the text[2] or bytestring[3]
 packages - the reduced size comes at a cost. Both of these libraries
 offer substring manipulation functions which allow the sharing of the
 backing memory buffers. Also, I haven't implemented any sort of
 string-like operations on the type as it isn't the right thing for
 that.

 I've borrowed heavily from the previously mentioned text package for
 the underlying array implementation, so thanks goes to Bryan
 O'Sullivan for maintaining the package and to all of the other authors
 as well.

 Take care,
 Antoine

 [1] http://hackage.haskell.org/package/smallstring
 [2] http://hackage.haskell.org/package/text
 [3] http://hackage.haskell.org/package/bytestring

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


This looks really cool! Suggestion - would it be more efficient to
provide direct text - smallstring or bytestring - smallstring
functions rather than forcing clients to go through String? That might
be useful e.g. if you were parsing (bytestring/text) data and building
a Map in the process.

Alex

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


Re: [Haskell-cafe] Crazy idea, building ghc with cabal?

2010-11-29 Thread Alexander Dunlap
On Mon, Nov 29, 2010 at 2:48 PM, Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com wrote:
 On 30 November 2010 03:46, Joris Putcuyps joris.putcu...@gmail.com wrote:
 Hello

 Could it be done and would it be interesting, building 'ghc' using
 cabal?

  * 'lhc' does it
  * Use 'cabal-rpm' and 'cabal2arch' to create packages for linux
   distributions
  * As ordinary user, install specific versions in your home
   directory.
   cabal install ghc = $HOME/.cabal/bin/ghc
  * Get base packages as a dependency.

 ... except we then have a chicken and egg problem: GHC is built with
 Cabal, which needs a Haskell compiler/implementation, etc. ;-)

 --
 Ivan Lazar Miljenovic
 ivan.miljeno...@gmail.com
 IvanMiljenovic.wordpress.com

Well, GHC is already written in Haskell, so you already need GHC to
compile GHC. I think the reasons are more to do with the fact that
Cabal doesn't have some features that are needed for such a complex
build as GHC, maybe including the bootstrapping that needs to happen.

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


Re: [Haskell-cafe] Re: [web-devel] statically compiled css

2010-08-08 Thread Alexander Dunlap
On Sun, Aug 8, 2010 at 4:00 AM, Michael Snoyman mich...@snoyman.com wrote:


 On Sun, Aug 8, 2010 at 1:03 PM, Tim Matthews tim.matthe...@gmail.com
 wrote:

 On Sun, Aug 8, 2010 at 9:20 PM, Michael Snoyman mich...@snoyman.com
 wrote:

 Quick update: I'm including the Stylish code in the hamlet package now,
 and renaming it to Camlet (CSS-hamlet). I'm also including something
 called Jamlet, which doesn't do much besides variable interpolation. As
 you might guess, it's for Javascript. I mention it at the end of my most
 recent blog post[1].
 Michael

 While It's just a name and not really important: hamlet was haml so I
 first imagined sasset, sasslet or another name from one of the works of
 Shakespeare but I then really liked stylish as I thought it would tell that
 something with solid foundations and theory could still appear, hip and
 pretty.

 What is important though is the code. This is absolutely great and success
 just keeps getting harder to avoid.

 This is by no means a final decision; I'm open to being convinced that other
 names are better. But I'll point out the main reason for the Camlet/Jamlet
 name choice: easy to remember and type. I found stylish to be much harder
 to get out than camlet; that might just be because I'm so used to hamlet
 already, but that's exactly my goal here: make these three templating
 systems work together nicely to make the developers life a little bit
 easier.
 Michael
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe



CaSSius and JSaesar?

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


Re: [Haskell-cafe] Maybe to Either -- is there a better way?

2010-08-04 Thread Alexander Dunlap
On Wed, Aug 4, 2010 at 9:21 AM, Henning Thielemann
schlepp...@henning-thielemann.de wrote:
 Ivan Lazar Miljenovic schrieb:
 Yitzchak Gale g...@sefer.org writes:

 While useful, I think its ubiquity to simplicity ratio is not
 high enough to justify either depending on MissingH
 just for that, or adding it to a base library.

 Just like the swap :: (a,b) - (b,a) function a lot of people were
 discussing on librar...@?

 I have 'swap' in my utility-ht.

 In general, I agree.

 Problem in Haskell is, that it allows for a high degree of
 modularization such that most components become trivial. Does that mean
 that we should not define simple functions at all, which in the extreme
 case would mean that we inline all potential function calls?


It's also nice for people reading code if common functions are
functions from common libraries. This allows readers' vocabulary of
common functions to increase, so they don't have to trawl through
someone's personal utility library to figure out what each utility
function does.

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


Re: [Haskell-cafe] Handling absent maintainers

2010-07-24 Thread Alexander Dunlap
One issue that comes up is that when you fork a package, data can no
longer be freely exchanged between libraries using the original
package's datatypes and libraries using the forked package's
datatypes. Something that might help here is the concept of
extension or friend packages or modules: packages or modules that
could break through to access concrete representations of abstract
datatypes or classes. The advantage would be that in many cases,
instead of forking a package, you could make the necessary changes
through a tightly-coupled but separately-maintained friend package
while still maintaining compatibility with the original package.

This wouldn't help for the problem of maintaining a package that
wouldn't compile. That might be helped by something like a provides
or equivalent field, where Cabal could be informed that a new
package should be treated as satisfying a dependency on a different
package.

Alex

On Fri, Jul 23, 2010 at 11:36 PM, Mark Wotton mwot...@gmail.com wrote:
 That works fine for my own stuff, but I'd like it to work for people
 using my software that relies on those packages.

 mark

 On Sat, Jul 24, 2010 at 4:10 PM, Roman Beslik ber...@ukr.net wrote:
  I patch broken packages in my local repository. I increment a version so
 the local repository get a precedence over the Hackage.

 On 16.07.10 03:54, Mark Wotton wrote:

 2. run my own hackage server and tell my users to use that instead.

 --
 Best regards,
  Roman Beslik.





 --
 A UNIX signature isn't a return address, it's the ASCII equivalent of a
 black velvet clown painting. It's a rectangle of carets surrounding a
 quote from a literary giant of weeniedom like Heinlein or Dr. Who.
         -- Chris Maeda
 ___
 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] Haskell and the Software design process

2010-05-02 Thread Alexander Dunlap
On Sun, May 2, 2010 at 9:24 PM, Ivan Miljenovic
ivan.miljeno...@gmail.com wrote:
 On 3 May 2010 14:17, aditya siram aditya.si...@gmail.com wrote:
 I'm a little confused about this too. I've seen many functions defined like:
 f x = (\s - ...)
 which is a partial function because it returns a function and is the same as:
 f x s = ...

 No, that's a partially applied function.

 A partial function is one such as:

 secondElement (_:x:_) = x

 Note that it is only defined for lists with at least two elements, for
 any other list (i.e. singleton or empty) it will throw an error;
 -fwarn-incomplete-patterns (which is included in -Wall) tells you
 about these.

 You can also argue that functions such as head are partial, as they
 explicitly throw an error if the input data isn't correct.

 Partial functions are bad because if you accidentally use one the
 wrong way, your entire program crashes in a flaming wreck.  It's much
 better to do something like this:

 safeSecondElement (_:x:_) = Just x
 safeSecondElement _         = Nothing

 This will work with all possible input types.

 For more information, see
 http://en.wikipedia.org/wiki/Partial_function (from the mathematical
 perspective).

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


Of course, there are situations where it is really awkward to not use
partial functions, basically because you *know* that an invariant is
satisfied and there is no sane course of action if it isn't. To take a
contrived example:

f ys = let xs = (1:ys) in last xs

uses the partial function last. Rewriting it in the non-partial style gives

f ys = case (1:ys) of
  [] - Nothing
  xs - Just (last xs)

but what possible meaning could a caller of the function ascribe to a
Nothing result? It just means that there is a bug in f, which is
what an error would tell you anyway. Of course, this particular
function could easily be rewritten in such a way to be total, but I
believe there are more complex examples where it is awkward/impossible
to do so.

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


Re: [Haskell-cafe] Splitting list with predicate

2010-03-14 Thread Alexander Dunlap
On Sun, Mar 14, 2010 at 12:26 PM, michael rice nowg...@yahoo.com wrote:

 Is there a library function that will create two lists from one based on a 
 predicate, one list for all elements that satisfy the predicate and one for 
 all that do not? Don't want to reinvent the wheel.

 Michael




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


Data.List.filter will do the trick.

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


Re: [Haskell-cafe] Prelude.undefined

2010-03-02 Thread Alexander Dunlap
On Tue, Mar 2, 2010 at 9:06 PM, Tom Hawkins tomahawk...@gmail.com wrote:
 How do I track down an reference to an undefined value?  My program
 must not be using a library correctly because the program makes no
 direct use of 'undefined'.  Running with +RTS -xc yields:

 GHC.Err.CAFTest: Prelude.undefined
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


While the debugger, etc., are very useful tools, I find that often the
easiest way to track down this sort of bug is to test your code
function-by-function. Make sure each function does what you want it to
when run in isolation; this will quickly lead to tracking down the
caller of undefined. (If your code is not structured in a way that
allows this sort of testing, you might consider restructuring it to
make it more modular.)

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


Re: [Haskell-cafe] ANN: HPath-0.0.0

2009-12-30 Thread Alexander Dunlap
On Tue, Dec 29, 2009 at 11:52 PM, Jason Dusek jason.du...@gmail.com wrote:
  HPath is a command line utility to grab the Haskell source
  for a given identifier:

  :; dist/build/hpath/hpath HPath.Path.parse 2/dev/null
 parse                       ::  String - Either ParseError Path
 parse s = Text.ParserCombinators.Parsec.parse (qualified []) s s

  This is an alpha release. There are many things HPath can't
  retrieve -- like constructors -- and there seem to be some
  complications with the underlying parser/pretty printer (some
  times you get far too many newlines).

  There will be another release when the newline issue is
  resolved. The hope is to release HPath in conjunction with
  LaTeX macros to allow easy inclusion of Haskell in elaborate
  documents.

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


The package doesn't build with haskell-src-exts version 1.5.1 (the
latest version on Hackage). It would be good to either make it build
with HSE 1.5.1 or else put a maximum version of HSE in your .cabal
file so that Cabal can select a lower version of HSE if available.

Looks like an interesting package; I'm looking forward to trying it out!

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


Re: [Haskell-cafe] Space Efficiency When Sorting a List of Many Lists

2009-12-30 Thread Alexander Dunlap
On Wed, Dec 30, 2009 at 8:39 PM, Peter Green kinch1...@me.com wrote:
 I'm a Haskell neophyte, so may be missing something obvious in the problem
 outlined below. I'm fairly proficient in Python + have some limited
 experience in OCaml and F#, so know just enough to be be dangerous, but not
 nearly enough to really know what I'm doing here.

 OK, I have text files containing 'compressed lists' Compressed lists look
 like this:

 8+12,11,7+13,10
 1+2+3,1+9,3+6,4
 .
 .

 Sublists are comma-delimited, and sublist elements are separated by '+'
 character.

 I parse these to look like so:

 [[[8,12],[11],[7,13],[10]],
  [[1,2,3],[1,9],[3,6],[4]],
 .
 .
 ]

 I need to explode these and produce a lex-sorted list of exploded lists:

 [[1,1,3,4],[1,1,6,4],[1,9,3,4],[1,9,6,4],[2,1,3,4],[2,1,6,4],[2,9,3,4],[2,9,6,4],[3,1,3,4],[3,1,6,4],[3,9,3,4],[3,9,6,4],
  [8,11,7,10],[8,11,13,10],[12,11,7,10],[12,11,13,10]]

 I then output this data as comma-delimited lists:

 1,1,3,4
 1,1,6,4
 .
 .
 12,11,13,10

 I can do all this in my (no doubt fairly naive) program shown below. In real
 life, one of my test data files contains compressed lists which all contain
 7 sublists. This data (correctly) explodes to a list containing ~3,700,000
 exploded lists. All good as far as correctly transforming input to output
 goes. However, sorting the data uses a lot of memory:

 Partial output from ./explode +RTS -sstderr:

 540 MB total memory in use (4 MB lost due to fragmentation)

 If I do not do any sorting on the exploded lists, i.e. modify the main
 function to be
        main = interact (unlines . toCSV . explode . fromCSV . lines)

 I then see this partial output from ./explode +RTS --stderr:

 2 MB total memory in use (0 MB lost due to fragmentation)

 I can guess that there might be be less laziness and more instantiation when
  sorting is introduced, but my questions are:
        (1) Am I doing anything terribly stupid/naive here?
        (2) If so, what can I do to improve space efficiency?

 TIA!


 import Data.List (sort)
 import Data.List.Split (splitOn)

 -- Cartesian Product over a List of Lists
 -- cp [[1,2],[3],[4,5,6]] --
 [[1,3,4],[1,3,5],[1,3,6],[2,3,4],[2,3,5],[2,3,6]]
 cp          :: [[a]] - [[a]]
 cp []       =  [[]]
 cp (xs:xss) =  [y:ys | y - xs, ys - cp xss]

 -- fromCSV [8+12,11,7+13,10, 1+2+3,1+9,3+6,4] --
 -- [[[8,12],[11],[7,13],[10]],[[1,2,3],[1,9],[3,6],[4]]]
 fromCSV :: [String] - [[[Int]]]
 fromCSV = map parseOneLine
    where parseOneLine = map parseGroup . splitOn ,
              where parseGroup = map read . splitOn +

 -- explode [[[1,2],[3],[4,5,6]], [[1, 2], [14,15], [16]]] --
 [[1,3,4],[1,3,5],
 -- [1,3,6],[2,3,4],[2,3,5],[2,3,6],[1,14,16],[1,15,16],[2,14,16],[2,15,16]]
 explode :: [[[a]]] - [[a]]
 explode =  concatMap cp

 -- toCSV [[8,11,7,10,12],[8,11,7,10,12],[8,11,7,10,12]] --
 -- [8,11,7,10,12,8,11,7,10,12,8,11,7,10,12]
 toCSV :: (Show a) = [[a]] - [String]
 toCSV = map $ tail . init . show
 --toCSV = map (intercalate , . map show)

 main = interact (unlines . toCSV . sort . explode . fromCSV . lines)

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


I'm not sure about your problem specifically but the external-sort
package on Hackage may be of interest.

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


Re: [Haskell-cafe] Use of the Try typeclass

2009-12-30 Thread Alexander Dunlap
On Wed, Dec 30, 2009 at 5:52 PM, Edward Z. Yang ezy...@mit.edu wrote:
 Hello all,

 I am currently playing with the new cadre of failure libraries, and I'm
 trying to figure out how to use the monadic version of Failure while
 also getting the Try typeclass, which appears to be the standardized mechanism
 for marshalling values from specific monads into the failure monad.
 Unfortunately, it only seems to be defined when I import Control.Failure,
 and this module is fairly incompatible with Control.Monad.Failure, as
 demonstrated by this GHCI transcript:

    ezy...@javelin:~/Documents/tmr$ ghci
    Prelude :m +Control.Failure
    Prelude Control.Failure :m +Control.Monad.Failure
    Prelude Control.Failure Control.Monad.Failure :t failure

    interactive:1:0:
        Ambiguous occurrence `failure'
        It could refer to either `Control.Failure.failure', imported from 
 Control.Failure
                              or `Control.Monad.Failure.failure', imported 
 from Control.Monad.Failure

 I'm using MTL, which might be the reason why there's all sorts of 
 unhappiness. :-)

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


Why are you importing both Control.Failure and Control.Monad.Failure
when the latter just re-exports the former? Are you using the latest
versions of the two packages? Try importing just
Control.Monad.Failure.MTL; that provides the MTL failure instances and
also re-exports Control.Failure.

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


Re: [Haskell-cafe] Use of the Try typeclass

2009-12-30 Thread Alexander Dunlap
On Wed, Dec 30, 2009 at 10:54 PM, Edward Z. Yang ezy...@mit.edu wrote:
 Excerpts from Michael Snoyman's message of Thu Dec 31 00:43:52 -0500 2009:
 What version of the packages are you using? Can you give the output of:

 ghc-pkg list|grep failure

 Sure thing:

    (control-monad-failure-0.4), (control-monad-failure-0.5.0),
    control-monad-failure-mtl-0.5.0, cpphs-1.8, cpphs-1.9,
    failure-0.0.0.1, happstack-0.3.2, happstack-data-0.3.3

 Additionally:

 ezy...@javelin:~$ cabal upgrade failure
 Resolving dependencies...
 No packages to be installed. All the requested packages are already installed.
 If you want to reinstall anyway then use the --reinstall flag.

 Cheers,
 Edward


Upgrade to control-monad-failure-mtl 0.6.0 and control-monad-failure 0.6.0.

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


Re: [Haskell-cafe] Perhaps you haven't installed the dyn libraries

2009-12-29 Thread Alexander Dunlap
On Tue, Dec 29, 2009 at 11:34 AM, Gregory Propf gregorypr...@yahoo.com wrote:

 I'm trying out the dynamic linking in GHC 6.12 and getting this message a lot 
 for different libraries.  I assume I need to rebuild them with different ghc 
 options in the cabal files and have tried -shared, -dynamic and -fPIC but 
 with no luck.  Is there something I'm missing.


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


Use the --enable-shared option to cabal install. If you want dynamic
libraries everywhere, put shared: True in ~/.cabal/config. You'll need
to recompile all of your libraries.

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


Re: [Haskell-cafe] New Hackage category: Error Handling

2009-12-06 Thread Alexander Dunlap
On Sat, Dec 5, 2009 at 3:00 PM, Michael Snoyman mich...@snoyman.com wrote:


 On Sun, Dec 6, 2009 at 12:55 AM, Henning Thielemann
 lemm...@henning-thielemann.de wrote:

 On Sun, 6 Dec 2009, Michael Snoyman wrote:

 I think there are plenty of examples like web servers. A text editor with
 plugins? I
 don't want to lose three hours worth of work just because some plugin
 wasn't written
 correctly. For many classes of programs, the distinction between error
 and exception is
 not only blurred, it's fully irrelevant. Harping on people every time
 they use error in
 the wrong sense seems unhelpful.

 Hope my commenting on this subject doesn't become my own form of
 *pedantry*.

 In an earlier thread I have explained that one can consider a software
 architecture as divided into levels. What is an error in one level (text
 editor plugin, web server thread, operating system process) is an exception
 in the next higher level (text editor, web server, shell respectively). This
 doesn't reduce the importance to distinguish between errors and exceptions
 within one level. All approaches so far that I have seen in Haskell just mix
 exceptions and errors in an arbitrary way.

 I think we can all appreciate why it would be a bad thing is we treat
 exceptions as errors. For example, I don't want my program to crash on a
 file not found.

 On the other hand, what's so bad about treating errors as exceptions? If
 instead of the program crashing on an array-out-of-bound or pattern-match it
 throws an exception which can be caught, so what?

 Michael


I think the key is in the difference between the user/client and
programmer/developer. As Henning has been saying, these roles change
as you go through the different levels of the program, but I see the
difference between an error and an exception as this: when a problem
is relevant to the user/client, it's an exception; when it is
irrelevant to the user/client, it's an error. Suppose you were using
some sort of exception framework and you got an error from a piece of
library code (not the head function) saying that head had failed
somewhere. This is absolutely meaningless to a client. It just means
there's a problem in the library code; it doesn't mean anything is
amiss in the client's space. The client basically has to throw the
function out, whether by gracefully aborting the program, disabling
the plugin, etc. Contrast this with an exception, such as index not
in map. This is entirely relevant to the client. All of the code
knows exactly what is going on; it's just that the index isn't in the
map. The client can recover from this by, say, substituting a default
value, adding the index to the map, etc. Now, suppose the client knew
a priori that the index was *supposed* to be in the map. Now this
becomes an *error* to the *client* of the client, since there is a bug
in the first client's code.

I guess my point is that if I have a function, say, sort :: Ord a =
[a] - [a], and sort calls head somewhere in it, there's no point
having sort throw an exception for Prelude.head: [] since that
means nothing to the client. It would make more sense to have an
InternalError type that just says OK, sorry client, I screwed up,
just clean things up as best you can. If really were something that
the client could have responded to, sort should have caught the head
error inside the function definition and rethrown a different
exception; say, SortEmptyListError if your sort function didn't work
on empty lists (contrived example, sorry).

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


Re: [Haskell-cafe] New Hackage category: Error Handling

2009-12-06 Thread Alexander Dunlap
On Sun, Dec 6, 2009 at 10:40 PM, Alexander Dunlap
alexander.dun...@gmail.com wrote:
 On Sat, Dec 5, 2009 at 3:00 PM, Michael Snoyman mich...@snoyman.com wrote:


 On Sun, Dec 6, 2009 at 12:55 AM, Henning Thielemann
 lemm...@henning-thielemann.de wrote:

 On Sun, 6 Dec 2009, Michael Snoyman wrote:

 I think there are plenty of examples like web servers. A text editor with
 plugins? I
 don't want to lose three hours worth of work just because some plugin
 wasn't written
 correctly. For many classes of programs, the distinction between error
 and exception is
 not only blurred, it's fully irrelevant. Harping on people every time
 they use error in
 the wrong sense seems unhelpful.

 Hope my commenting on this subject doesn't become my own form of
 *pedantry*.

 In an earlier thread I have explained that one can consider a software
 architecture as divided into levels. What is an error in one level (text
 editor plugin, web server thread, operating system process) is an exception
 in the next higher level (text editor, web server, shell respectively). This
 doesn't reduce the importance to distinguish between errors and exceptions
 within one level. All approaches so far that I have seen in Haskell just mix
 exceptions and errors in an arbitrary way.

 I think we can all appreciate why it would be a bad thing is we treat
 exceptions as errors. For example, I don't want my program to crash on a
 file not found.

 On the other hand, what's so bad about treating errors as exceptions? If
 instead of the program crashing on an array-out-of-bound or pattern-match it
 throws an exception which can be caught, so what?

 Michael


 I think the key is in the difference between the user/client and
 programmer/developer. As Henning has been saying, these roles change
 as you go through the different levels of the program, but I see the
 difference between an error and an exception as this: when a problem
 is relevant to the user/client, it's an exception; when it is
 irrelevant to the user/client, it's an error. Suppose you were using
 some sort of exception framework and you got an error from a piece of
 library code (not the head function) saying that head had failed
 somewhere. This is absolutely meaningless to a client. It just means
 there's a problem in the library code; it doesn't mean anything is
 amiss in the client's space. The client basically has to throw the
 function out, whether by gracefully aborting the program, disabling
 the plugin, etc. Contrast this with an exception, such as index not
 in map. This is entirely relevant to the client. All of the code
 knows exactly what is going on; it's just that the index isn't in the
 map. The client can recover from this by, say, substituting a default
 value, adding the index to the map, etc. Now, suppose the client knew
 a priori that the index was *supposed* to be in the map. Now this
 becomes an *error* to the *client* of the client, since there is a bug
 in the first client's code.

 I guess my point is that if I have a function, say, sort :: Ord a =
 [a] - [a], and sort calls head somewhere in it, there's no point
 having sort throw an exception for Prelude.head: [] since that
 means nothing to the client. It would make more sense to have an
 InternalError type that just says OK, sorry client, I screwed up,
 just clean things up as best you can. If really were something that
 the client could have responded to, sort should have caught the head
 error inside the function definition and rethrown a different
 exception; say, SortEmptyListError if your sort function didn't work
 on empty lists (contrived example, sorry).

 Alex


(Sorry for replying to myself.)

This is, of course, assuming that a non-empty list was not an
invariant of the sort function, in which case it would be a
programming error on the part of the client that called sort if that
happened.

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


Re: [Haskell-cafe] instance Binary UTCTime (Was: Oprhan instances)

2009-11-29 Thread Alexander Dunlap
On Sun, Nov 29, 2009 at 5:37 AM, Duncan Coutts
duncan.cou...@googlemail.com wrote:
 On Thu, 2009-11-26 at 16:40 -0500, David Menendez wrote:

 The problem with this solution is that it doesn't scale. If we have M
 packages providing types and N packages providing classes, then we
 need M*N additional packages for orphans.

 The best long-term solution is probably extending Cabal to handle this
 more transparently, perhaps by allowing packages to depend on flagged
 versions of other packages (e.g., foomonad = 4.0   4.1  HAS_MTL)

 Not going to happen. Such packages could not be translated into binary
 distro packages.

 Duncan


Wouldn't the distro just choose one set of flags for each package and
then other packages would either be satisfied or not satisfied based
on which flags had been chosen? It seems to me that distros could even
offer multiple options for the same package with different flags set.
What wouldn't work?

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


Re: [Haskell-cafe] instance Binary UTCTime (Was: Oprhan instances)

2009-11-29 Thread Alexander Dunlap
On Sun, Nov 29, 2009 at 4:41 PM, Duncan Coutts
duncan.cou...@googlemail.com wrote:
 On Sun, 2009-11-29 at 09:55 -0800, Alexander Dunlap wrote:
 On Sun, Nov 29, 2009 at 5:37 AM, Duncan Coutts
 duncan.cou...@googlemail.com wrote:
  On Thu, 2009-11-26 at 16:40 -0500, David Menendez wrote:
 
  The problem with this solution is that it doesn't scale. If we have M
  packages providing types and N packages providing classes, then we
  need M*N additional packages for orphans.
 
  The best long-term solution is probably extending Cabal to handle this
  more transparently, perhaps by allowing packages to depend on flagged
  versions of other packages (e.g., foomonad = 4.0   4.1  HAS_MTL)
 
  Not going to happen. Such packages could not be translated into binary
  distro packages.
 
  Duncan
 

 Wouldn't the distro just choose one set of flags for each package and
 then other packages would either be satisfied or not satisfied based
 on which flags had been chosen?

 Here's the system I assumed you were talking about. You can tell me if I
 misunderstood.

 Instead of having N * M packages, you have a package that provides
 optional instances. For example package A defines a class and
 optionally provides instances for types defined in B. If you select to
 have it depend on B then the instances are provided, otherwise not.

 In a source based system this seems to work ok, you would provide
 optional instances for all the packages you already happen to have
 installed. Though if later you install another package that could have
 had optional instances provided then you have to go recompiling things.

 It's slightly worse for binary packages because the distro has to decide
 up front if they're going to provide the optional instances or not.
 Since someone might need them then you end up picking the maximal set of
 optional dependencies and you end up pulling in all sorts of apparently
 unrelated packages.

 Then the other bit you suggested foomonad = 4.0   4.1  HAS_MTL
 would be needed to be able to express that you want a package that has
 been built with a particular optional instance provided. This is the bit
 that cannot be translated into packages in most distros. Yes you could
 pick the flags up front, but you have to pick a single assignment that
 satisfies everyone.

Well, that happens anyway with most packages since distros have to
choose one set of flags that works. The proposal I was commenting on
would just allow packages to depend on flags of other packages and so
be explicit about this.


 It seems to me that distros could even offer multiple options for the
 same package with different flags set.

 Most distros cannot handle installing multiple instances of the same
 version of a package.

Well, what I've seen is having different packages, i.e.
foo-quickcheck, foo-no-quickcheck as separate packages.

(Note that I can't take credit for suggesting the idea, I was just
asking you about your objection.)

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


Re: [Haskell-cafe] Re: Newcomers question

2009-11-01 Thread Alexander Dunlap
The type of liftA2 :: Applicative f =(a - b - c) - f a - f b - f
c. Thus, the type of liftA2 (==) :: (Eq b, Applicative f) = f b - f
b - f Bool. In your case, f :: a - b, so liftA2 (==) :: (Eq b) = (a
- b) - (a - b) - (a - Bool). (==) takes two arguments, so you're
left with the type (liftA2 (==)) x y :: a - Bool. This contradicts
the class definition of Eq, which says that the type of (==) after
giving it two arguments must be Bool, not a - Bool.

I hope that's clear enough. Busting out GHCi and using :t to find the
types of a lot of these expressions can be really helpful.

Alex

On Sun, Nov 1, 2009 at 8:09 AM, b1g3ar5 nick.st...@gmail.com wrote:
 OK, I understand that now but I've got a supplimentary question.

 If I put:

 instance Eq b = Eq (a - b) where
    (==) = liftA2 (Prelude.==)

 to do the Eq part I get another error:

    Couldn't match expected type `Bool'
           against inferred type `a - Bool'
    In the expression: liftA2 (==)
    In the definition of `==': == = liftA2 (==)
    In the instance declaration for `Eq (a - b)'

 Now can someone please explain this?

 I'm hoping that when I've understood this stuff I'll have made a small
 step to understanding Haskell.

 Thanks.


 On 31 Oct, 23:38, Daniel Peebles pumpkin...@gmail.com wrote:
 For some reason, Show and Eq are superclasses of Num (despite Num not
 actually using any of their methods), meaning that the compiler forces
 you to write instances of Eq and Show before it even lets you write a
 Num instance. I don't think anybody likes this, but I think we're
 stuck with it for the foreseeable future.



 On Sat, Oct 31, 2009 at 7:31 PM, b1g3ar5 nick.st...@gmail.com wrote:
  I'm trying:

  instance Num b = Num (a - b) where
  fromInteger = pure . Prelude.fromInteger
  negate = fmap Prelude.negate
  (+) = liftA2 (Prelude.+)
  (*) = liftA2 (Prelude.*)
  abs = fmap Prelude.abs
  signum = fmap Prelude.signum

  but the compiler rejects it with:

  src\Main.hs:24:9:
     Could not deduce (Show (a - b), Eq (a - b))
       from the context (Num b)
       arising from the superclasses of an instance declaration
                    at src\Main.hs:24:9-29
     Possible fix:
       add (Show (a - b), Eq (a - b)) to the context of
         the instance declaration
       or add an instance declaration for (Show (a - b), Eq (a - b))
     In the instance declaration for `Num (a - b)'

  Could someone please explain this to me?

  I thought that it might be that it couldn't work out the functions
  necessary for (a-b) to be in the classes Show and Eq - so I tried
  adding definitions for == ans show, but it made no difference.

  Thanks

  ___
  Haskell-Cafe mailing list
  haskell-c...@haskell.org
 http://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] tips on installing System.Console.Readline

2009-10-26 Thread Alexander Dunlap
On Mon, Oct 26, 2009 at 12:52 AM, Michael Mossey m...@alumni.caltech.edu 
wrote:
 Before I ask my main question, incidentally has anyone noticed that the GHCI
 prompt, on Windows XP, now has auto-completion! (since 6.10) Awesome!

 I'm trying to install System.Console.Readline on Windows XP. I need to have
 GNU readline installed first, which I did (by multiple methods). But running
 'cabal install readline' it reports that readline is not found. Obviously I
 need to set a path or environment variable... can anyone help?

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


Try the --extra-include-dirs and --extra-lib-dirs options to Cabal. If
there's a configure script, you might also need to modify the options
to that.

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


Re: [Haskell-cafe] Different semantics in identical do statement?

2009-10-09 Thread Alexander Dunlap
On Fri, Oct 9, 2009 at 4:25 PM, David Menendez d...@zednenem.com wrote:
 On Fri, Oct 9, 2009 at 6:47 PM, staafmeister g.c.stave...@uu.nl wrote:

 Daniel Peebles wrote:

 I vaguely remember on IRC someone pointing out that the Parsec monad
 broke one of the laws. I think return _|_  x === _|_ which could be
 causing your problem. I may be wrong though.



 Confirmed, working in the parsec monad

 Prelude Text.Parsec runP (do {x - return undefined; return 10}) ()  
 *** Exception: Prelude.undefined

 In the IO Monad
 Prelude Text.Parsec do {x - return undefined; return 10}
 10

 Should be fixed.

 It looks like the problem is a strict field in the definition of
 GenParser (specifically in Reply). From what I can tell, Parsec 3.0.1
 should not have this problem.

 --
 Dave Menendez d...@zednenem.com
 http://www.eyrie.org/~zednenem/
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


It works with Parsec 3.0.1 for me.

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


Re: Re: [Haskell-cafe] Problem with result-type context restrictions in typeclasses.

2009-09-30 Thread Alexander Dunlap
I think

instance Bar (Ret c) = Foo c where
  ...

will do what you are asking.

Alex

On Tue, Sep 29, 2009 at 10:25 PM, DNM dnme...@gmail.com wrote:

 Dan, thanks again for the response.

 I changed my code to use type families to let each Cls instance (actually a
 more complicated instance in my code) determine which Bar instance type it
 will return, but this didn't seem to work.  The problem is that the client
 of the typeclass instance methds ('useThisStuff', which calls on 'toNum' and
 'foo' in the contrived example) expects some guarantee that (Ret c) is going
 to be an instance of Bar.  The actual client code I'm using complains when
 it sees that the associated type doesn't guarantee that an instance of the
 appropriate class is instantiated.  I don't see any way to guarantee this
 without adding a context restriction in the class-level definition of Ret c,
 something like:

 class Cls c where
   type Ret c :: (Bar *) = * -- or a better name
   foo :: c - Ret c

 which isn't legal Haskell.  What I want to say is define Ret c however you
 want, but make sure it is an instance of Bar in the *class-level definition
 of Ret c*, so that any client of 'Cls' will know that Ret c will be
 foo-able.

 Maybe I'm missing some subtlety of type families...

 Any suggestions?

 --D.N.


 Daniel Peebles wrote:

 In your class, you have:

 class Cls c where
    foo :: (Bar b) = c - b

 There's an implicit forall for b, meaning that the caller of the
 method gets to choose what it wants for b (as long as it's an instance
 of Bar). For you to be able to write such a method you'd need to write
 functions that can return any instance of Bar. One solution to this is
 to turn on the GHC extension -XTypeFamilies, and then modify your code
 as follows:

 class Cls c where
    type Ret c :: * -- or a better name
    foo :: c - Ret c

 instance Cls G where
    type Ret G = FU
    foo = fuu

 That should work (although I haven't tested it).

 What type families do in this case is allow you to write not only
 methods associated with typeclasses, but type functions associated
 with them too. In this case you can think of Ret as a function that
 takes a type (G in the instance above) and returns another type (FU).
 Each instance can define new mappings for Ret.

 Hope this helps!

 Dan
 On Tue, Sep 29, 2009 at 10:48 PM, DNM dnme...@gmail.com wrote:
 Correction by the author:

 It seems that ghc doesn't like the fact that I am saying 'foo' must
 return a class 'b' of typeclass 'Bar', while providing a function that
 returns a concrete data instance of 'Bar' (viz., FU or FI) later on
 when I implement 'foo' in each type classes.

 Should read:

 It seems that ghc doesn't like the fact that I am saying 'foo' must
 return something of TYPE 'b' implementing typeclass 'Bar', while
 providing
 a function that returns a concrete data instance of 'Bar' (viz., FU or
 FI)
 later on when I implement 'foo' in each type classes.

 On Sep 29, 10:43 pm, DNM dnme...@gmail.com wrote:
 N.B. I'm a newbie to Haskell, and this problem is a bit complex, so
 bear with me.

 I'm using typeclasses to implement a sort of common interface for all
 things -- call them things of type 'Cls' -- that can be expected to
 implement a set of functions -- an 'interface' in OOP-speak.  (Yes,
 yes, I'm aware that typeclasses are subtly different and far superior,
 but my Haskell-ese is still a bit rudimentary.)

 Essentially, I want to have a typeclass that expects its instances to
 have an accessor function that results in something that is an
 instance of another typeclass whose instances can perform some
 operation.   The ghc type-checker doesn't seem to like my code,
 though, and I can't seem to figure out why.

 To make it concrete, I've typed up some dummy typeclasses and a dummy
 function that uses their instances to illustrate what I mean, as well
 as the form of the ghc(i) error.

 - BEGIN CODE --
 class Cls c where
     foo :: (Bar b) = c - b

 class Bar b where
     toNum :: b - Int

 -- | One implementation of Cls
 data D = D {fu :: FU}
 data FU = FU {num :: Int}

 instance Cls D where
     foo = fu
 instance Bar FU  where
     toNum f = (num f) + 47

 -- | Another implementation of Cls
 data E = E {fi :: FI}
 data FI = FI {nuum :: Int}

 instance Cls E where
     foo = fi
 instance Bar FI where
     toNum f = (nuum f) + 100

 -- | Yet another (this one re-uses FI)
 data F = F {fii :: FI}

 instance Cls F where
     foo = fii

 -- | And one last one, just to stress that
 --   I really need to implement multiple
 --  instances of Cls.
 data G = G {fuu :: FU}

 instance Cls G where
     foo = fuu

 -- | Good. Now, the function 'useThisStuff' need
 --   not know anything about it's payload
 --   other than that it its args are Cls's
 --   (hence they are foo'able things that
 --   can be used to construct an Int answer).
 useThisStuff :: (Cls x, Cls y) = x - y - Int
 useThisStuff x y =
     (toNum $ foo x) + (toNum $ foo y)
 

Re: [Haskell-cafe] error on --++ bla bla bla

2009-09-30 Thread Alexander Dunlap
Comments are started with -- followed by a character that is not a
symbol character. If it is followed by a symbol character (e.g. *)
then the -- plus the symbol (e.g. --*) parses as an operator
rather than a comment. p is not a symbol, so the -- starts a
comment.

For a precise description of Haskell syntax, see the Haskell98
Report[1]. It's quite readable, at least in comparison to other
precise documents I've attempted to read.

Hope that helps.

Alex

On Wed, Sep 30, 2009 at 7:48 PM, Hong Yang hyang...@gmail.com wrote:
 Nowhere any Haskell book mentioned line comments start with -- , not just
 --. It is just people usually put --  ahead of comments.

 I can successfully compile --print bla bla bla.
 On Wed, Sep 30, 2009 at 7:36 PM, Sebastian Sylvan
 sebastian.syl...@gmail.com wrote:


 On Thu, Oct 1, 2009 at 12:52 AM, Hong Yang hyang...@gmail.com wrote:

 Hi,

 I got an error if one of lines reads --++ bla bla bla where I tried to
 comment, but -- ++ bla bla bla (notice the space after --) is OK.

 Do you think this revealed a tiny bug in the GHC compiler (I am using
 Windows Haskell Platform 2009.2.0.2)?

 Line comments start with -- , not just --.
 --
 Sebastian Sylvan


 ___
 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] error on --++ bla bla bla

2009-09-30 Thread Alexander Dunlap
Oops...forgot the footnote. The lexical syntax part of the report is
at http://haskell.org/onlinereport/lexemes.html.

Alex

On Wed, Sep 30, 2009 at 7:56 PM, Alexander Dunlap
alexander.dun...@gmail.com wrote:
 Comments are started with -- followed by a character that is not a
 symbol character. If it is followed by a symbol character (e.g. *)
 then the -- plus the symbol (e.g. --*) parses as an operator
 rather than a comment. p is not a symbol, so the -- starts a
 comment.

 For a precise description of Haskell syntax, see the Haskell98
 Report[1]. It's quite readable, at least in comparison to other
 precise documents I've attempted to read.

 Hope that helps.

 Alex

 On Wed, Sep 30, 2009 at 7:48 PM, Hong Yang hyang...@gmail.com wrote:
 Nowhere any Haskell book mentioned line comments start with -- , not just
 --. It is just people usually put --  ahead of comments.

 I can successfully compile --print bla bla bla.
 On Wed, Sep 30, 2009 at 7:36 PM, Sebastian Sylvan
 sebastian.syl...@gmail.com wrote:


 On Thu, Oct 1, 2009 at 12:52 AM, Hong Yang hyang...@gmail.com wrote:

 Hi,

 I got an error if one of lines reads --++ bla bla bla where I tried to
 comment, but -- ++ bla bla bla (notice the space after --) is OK.

 Do you think this revealed a tiny bug in the GHC compiler (I am using
 Windows Haskell Platform 2009.2.0.2)?

 Line comments start with -- , not just --.
 --
 Sebastian Sylvan


 ___
 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] unicode text libraries

2009-09-28 Thread Alexander Dunlap
On Mon, Sep 28, 2009 at 9:15 AM, Don Stewart d...@galois.com wrote:
 tittoassini:
 2009/9/28 Don Stewart d...@galois.com:
  titto:
  Hi,
 
  I am looking for an unicode strings  library, I found on hackage:
 
  http://hackage.haskell.org/package/compact-string
 
  http://hackage.haskell.org/package/text
 
  They both look solid and functionally complete so ... I don't know which
  one to use :-)
 
  As I am sure I am not the first one facing this choice, may I ask
  which one you preferred and why?

  Data.Text

 Thanks , but .. why?

 Sorry, was on the way out the door. Data.Text has growing use, is well
 designed, and builds on the pedigree of bytestring and the vector*
 series of fusion libraries. I trust that code.

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


I just have a question out of curiosity - why was the decision made to
have Data.Text, uvector, and ByteString all separate data structures,
rather than defining the string types in terms of uvector?

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


Re: [Haskell-cafe] Re: HList and Type signatures / synonyms

2009-09-06 Thread Alexander Dunlap
2009/9/6 Günther Schmidt gue.schm...@web.de:
 Hi Edward,

 I suppose you're right, I could have made this a little more detailed.

 I keep reading in and processing data in an accumulating way, ie. lets say I
 have a DB table (don't take this literally please, just an example), into
 in-memory records of type

 data MyRecord = MyRecord {
        name :: String,
        birthDate :: LocalDate}

 in a second step I read in Gender information so now I'd need an extended
 Record

 data MyRecord = MyRecord {
        name :: String,
        birthDate :: LocalDate,
        gender :: Gender }

 and so on for another 12 times.

 In other words I need to extend the record.

 I had been using tuples, ie:

        (String, LocalDate) - Gender - (String, LocalDate, Gender)


 but after 6 or so *extensions* things get a tad messy.

 Anyway this is where HList really shines, but it is a bit akward when you
 want to state the type of an HList record, ie.


 type Entg =
    Record
    (HCons
     (LVPair (Label HZero) DRG)
     (HCons
      (LVPair (Label (HSucc HZero)) BelegungsTyp)
      (HCons
       (LVPair (Label (HSucc (HSucc HZero))) EntgeltBetrag)
       (HCons
        (LVPair (Label (HSucc (HSucc (HSucc HZero Zuschläge)
        (HCons
         (LVPair (Label (HSucc (HSucc (HSucc (HSucc HZero) Abschläge)
         HNil)

 which happens to be my actual stage 1 data type (Entg), one that has 5
 fields initial and in several distinct steps 8 more are *added*.



 So I wonder if there is a more simple way to do this, ie to *extend* the
 *type* signatures of extend records without such a lot of typing.

 Günther


 Am 07.09.2009, 02:44 Uhr, schrieb Edward Z. Yang ezy...@mit.edu:

 Excerpts from Günther Schmidt's message of Sun Sep 06 19:40:05 -0400 2009:

 I keep accumulating values and right now use plain tuples for that. I end
 up with a 12 element tuple and things are a bit messy.

 Hi, you may want to consider using the Writer monad. [1]

 I'd like to use extensible Records from HList instead, thing is I'd like
 to keep putting type signatures in my code. As it turns out that seems to
 be where it gets messy with HList.

 Perhaps more precisely explaining your problem domain would be useful.

 Cheers,
 Edward

 [1] http://www.haskell.org/all_about_monads/html/writermonad.html

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


Why don't you define your record to be the final set of all the
information that you will collect, and just leave some of the fields
undefined until you collect all the data? That would work well if you
are going to be collecting all of the data pretty much all at once.
You could also have a record of Maybe values that started out as all
Nothing and became Justs as the data was collected.

Maybe I'm misunderstanding your problem, but that's how I would do it.

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


Re: [Haskell-cafe] How to preload the module of my own

2009-09-04 Thread Alexander Dunlap
On Fri, Sep 4, 2009 at 6:08 PM, zaxisz_a...@163.com wrote:

 I want to preload the module automatically when starting ghci. The module
 located in ~/work directory contains some functions i use everyday.

 Now i use an alias: alias ghci='ghci -i ~/money/Money.hs' which works fine.
 However i feel there maybe are more elegant way.

 thanks!


If the module is part of a package you can put 'import NameOfModule'
in your ~/.ghc/.ghci file. That file contains commands that are run
when ghci starts. I'm not sure if you can load a module that isn't
installed.

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


Re: [Haskell-cafe] Re: Time constrained computation

2009-08-28 Thread Alexander Dunlap
On Fri, Aug 28, 2009 at 6:01 AM, Mitarmmi...@gmail.com wrote:
 Hi!

 Ups, missed save button and pressed send. ;-)

 So I am not really sure if this is correct term for it but I am open
 to better (search) terms.

 I am wondering if it is possible to make a time constrained
 computation. For example if I have a computation of an approximation
 of a value which can take more or less time (and you get more or less
 precise value) or if I have an algorithm which is searching some
 search-space it can find better or worse solution depending how much
 time you allow. So I would like to say to Haskell to (lazily, if it
 really needs it) get me some value but not to spend more than so much
 time calculating it.

 One abstraction of this would be to have an infinity list of values
 and I would like to get the last element I can get in t milliseconds
 of computational time.

 One step further would be to be able to stop computation not at
 predefined time but with some other part of the program deciding it is
 enough. So I would have a system which would monitor computation and a
 pure computation I would be able to stop. Is this possible? Is it
 possible to have a pure computation interrupted and get whatever it
 has computed until then?

 How could I make this? Is there anything already done for it? Some
 library I have not found?

 Of course all this should be as performance wise as it is possible.

 So the best interface for me would be to be able to start a pure
 computation and put an upper bound on computation time but also be
 able to stop it before that upper bound. And all this should be as
 abstracted as it is possible.


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


In general, you need to do this either within the IO monad, to avoid
breaking referential transparency, or using unsafePerformIO, if you
know that your use of it is safe, which seems somewhat unlikely.

You may want to look at System.Timeout. Another possibility would be
the unamb package from Hackage.

Hope that helps,
Alex
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] oauth in haskell - reviewers?

2009-08-23 Thread Alexander Dunlap
On Sun, Aug 23, 2009 at 9:25 AM, Diego Souzadso...@bitforest.org wrote:
 Hi Alex,

 - In the Token datatype, you can automatically create the accessor
 functions (oath_token, etc.) by using named fields:
 I though about that too and I was not sure about what to do. The reason
 I didn't use it is because I don't export the value constructors of
 Token type, that is why I created the access functions explicitly.

I'm pretty sure you can export just the access functions and not the
data constructors. They're just ordinary functions with a bit of
syntactic sugar, so they can be exported even if the constructors
aren't.

 - I think you can use join from Control.Monad and functions from
 Control.Applicative in your response function to make it quite a bit
 cleaner.
 To be honest I'm not familiar with Control.Applicative at all.  I'll
 read about it and see if I can figure how to do this.

 A quick search pointed me to this:
 http://www.soi.city.ac.uk/~ross/papers/Applicative.html

 Is there any other resources you would suggest me to read?


The rule of thumb I use is that you can replace

foo = do
  x1 - action1
  x2 - action2
  x3 - action3
  ...
  xn - actionn
  return (bar x1 x2 x3 ... xn)

by

foo = bar $ action1 * action2 * action3 * ... * actionn

for any number of actions. ($) is a synonym for fmap and (*) is
the same as Control.Monad.ap if the applicative functor is also a
monad. (All monads can be made instances of Applicative, and most
[all?] of the standard ones are.)

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


Re: [Haskell-cafe] oauth in haskell - reviewers?

2009-08-22 Thread Alexander Dunlap
On Sat, Aug 22, 2009 at 4:36 PM, Diego Souzadso...@bitforest.org wrote:
 Hi all,

 I wrote a small library in haskell do deal with oauth authentication. It
 turns out it is my first library in haskell as well. As I'm beginner in
 haskell, I'm asking for a review of someone more experienced/proficient
 before even daring to create a cabal pkg and dist it to hackage. :-)

 Any help/comments on this will be highly welcome.

 http://projects.bitforest.org/hoauth/

 $ darcs get http://projects.bitforest.org/hoauth/
 # should do the trick

 Thanks in advance,
 --
 ~dsouza
 yahoo!im: paravinicius
 gpg key fingerprint: 71B8 CE21 3A6E F894 5B1B  9ECE F88E 067F E891 651E
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


Hi,

I'm not familiar at all with OAuth but I have some general suggestions
that might make your code in Consumer.hs a bit nicer. These
suggestions also probably apply elsewhere in your code.

- In the Token datatype, you can automatically create the accessor
functions (oath_token, etc.) by using named fields:

data Token
  = Request { oath_token :: String, oath_token_secret :: String,
oath_extra :: R.Parameter }
  | Access { oath_token :: String, oath_token_secret :: String,
oath_extra :: R.Parameter }

This will create your accessor functions for free, and you get update
syntax to boot. (Google for haskell named fields for details.)

- When you have multiple datatype constructors with similar arguments
(as with Token or Request), it may be better to use a Boolean-type
flag saying which one it is (e.g. HTTP or HTTPS) and then a single
datatype with all of the different arguments in it. This may help you
remove code duplication elsewhere.

- I think you can use join from Control.Monad and functions from
Control.Applicative in your response function to make it quite a bit
cleaner.

I know this email has been a bit terse; ask if you have any questions
about the above.

Hope that helps,
Alex
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] gbp sign showing as unknown character by GHC

2009-08-19 Thread Alexander Dunlap
On Wed, Aug 19, 2009 at 11:08 AM, Iain Barnettiainsp...@gmail.com wrote:


 2009/8/19 David Leimbach leim...@gmail.com

 Interesting... GHCI bug?  Didn't the readline dependency go away not too
 long ago?  Could it be related?

 I just tried this
 Prelude putStrLn \£
 ghc: panic! (the 'impossible' happened)
   (GHC version 6.10.4 for i386-unknown-linux):
 charType: '\163'
 Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

 So perhaps I should put in a bug report, as that shouldn't happen (it
 doesn't with some other characters I tried), unless anyone has a different
 idea? I'm running Arch Linux with xmonad and using roxterm, so perhaps it's
 something to do with my setup?
 Iain


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



I can reproduce the panic on both urxvt and uxterm.

On urxvt, GHCi works correctly with putStrLn £. On uxterm, it just
prints a blank space.

I can type the GBP sign into both terminals.

Could it be a terminfo problem of some sort? It seems suspicious that
there is a difference between terminals.

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


[Haskell-cafe] Re: Thinking about what's missing in our library coverage

2009-08-03 Thread Alexander Dunlap
On Mon, Aug 3, 2009 at 4:44 PM, Don Stewartd...@galois.com wrote:

 Following Simon M's advice, I look over the typical batteries
 categories, using Python as input:

    http://docs.python.org/library/index.html

 The following things were missing from the current Platform. There are many.
 How would you identify the top, say, 5 libs to add?

 -- Don


    * String support
          o pcre regexes [pcre-light] [regex-pcre] — what’s our best regex lib?

For something like this, it seems like all of the regex libs probably
have pros and cons. It would be good if we could identify what these
are and create a library that was the best of all worlds instead of
just picking one and going with it.

          o unicode text [text] [text-icu] — packed, unicode text

This is essential, although I don't know if it is stable enough for
the platform (?).

    * text
          o pandoc — markdown, reStructuredText, HTML, LaTeX, ConTeXt, 
 Docbook, OpenDocument, ODT, RTF, MediaWiki, groff

No. Pandoc is too actively developed to go into the HP. It's also much
more of an end-user application than a standard library - it's
applications are not general enough to be included in the standard
distribution.

    * math and numerics
          o blas — BLAS
          o cmath — C math functions
          o dimensional — physical dimensions
          o fftw
          o mersenne-random — fast randoms

The interfaces here should be unified more to create a general Haskell
numerical library, IMO.

    * compression
          o bzip2
          o zip
          o tar

Definitely.

    * file formats
          o config parser

This would be quite useful.

    * crypto
          o hmac, md5, sha, hashing

Yes.

    * systems
          o getopt
          o logging
          o termio
          o editline
          o mmap

All of these, at some point.

    * Internet
          o network-bytestring
          o ssl
          o json
          o feed (rss, atom)
          o mime
          o base64 et al
          o uuencode
          o cgi
          o fastcgi
          o urls
          o ftp, http, imap, smtp clients
          o uuid
          o url parsing
          o http server
          o xml-rpc

Interface unification would help. Especially network-bytestring seems
to be too ad-hoc for me - it would probably be better to put
ByteString support into the regular Network library

    * Internationalization
          o gettext
          o locale
          o i18n

Yes, although again, maturity?

    * Development
          o hscolour

Yes.

My main concern is with libraries like attoparsec and
network-bytestring - these libraries seem to be somewhat ad-hoc
conversion of traditional libraries to use ByteStrings. We should come
up with a cleaner, more elegant way of dealing with the
String/Text/Strict ByteString/Lazy ByteSTring gap, as most libraries
that apply to one of those types also apply to the other two, as the
first two and last two especially and more generally all four
essentially represent the same thing. We shouldn't bless libraries
that don't have a good way of applying equally to these three.

A possible solution could be a standardized package-common,
package-string, package-text, package-bytestring,
package-lazybytestring naming convention, or a Category.Module,
Category.Module.String, Category.Module.ByteString.Strict,
Category.Module.ByteString.Lazy, Category.Module.Text convention. We
could also work something up with type classes. I just don't like how
a lot of libraries implement support for various string types just
based on need rather than creating a clean, comprehensive interface.

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


Re: [Haskell-cafe] TBC: Testing By Convention

2009-07-26 Thread Alexander Dunlap
On Sun, Jul 26, 2009 at 6:12 PM, Peter Gammiepete...@gmail.com wrote:
 Hello,

 Mark and I would like to announce our test harness, which has features
 complementary to existing harnesses.

 TBC provides two main features:
 - It attempts to compile and run all tests, even if some do not compile or
 run.
 - Aspiring to the write-it-once principle, tests following conventions
 require a lot less boilerplate.

 It is at an embryonic stage of development, and would greatly benefit from
 feedback and/or patches. :-)

 Hackage: http://hackage.haskell.org/package/TBC
 git: http://github.com/peteg/TBC/

 Enjoy!

 cheers
 peter

 --
 http://peteg.org/

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


Can it return an exit status based on whether or not all tests passed?
If not, that would be a very useful feature that I have not seen in
any other testing frameworks.

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


Re: [Haskell-cafe] following up on space leak

2009-07-05 Thread Alexander Dunlap
On Sun, Jul 5, 2009 at 7:46 PM, Uwe Hollerbachuhollerb...@gmail.com wrote:
 On 7/5/09, Paul L nine...@gmail.com wrote:
 Previously you had lastOrNil taking m [a] as input, presumably
 generated by mapM. So mapM is actually building an entire list before
 it returns the argument for you to call lastOrNil. This is where you
 had unexpected memory behavior.

 Now you are fusing lastOrNil and mapM together, and instead of
 building a list, you traverse it and perform monadic action along the
 way. This can happen in a constant memory if the original pure list is
 generated lazily.

 I think the real problem you had was a mis-understanding of mapM, and
 there was nothing wrong with your previous lastOrNil function. mapM
 will only return a list after all monadic actions are performed, and
 in doing so, it inevitably has to build the entire list along the way.

 --
 Regards,
 Paul Liu

 Yale Haskell Group
 http://www.haskell.org/yale

 Hi, Paul, thanks for the comments. You're quite right that I am fusing
 the two functions together, but I think I wasn't mis-understanding
 mapM... I knew I was generating the entire list, and aside from the
 slight inefficiency of generating it only to tear it down an instant
 later, that would have been no problem. But I was expecting all of the
 memory associated with the list to be reclaimed after I had processed
 it, and that was what was not happening as far as I could tell. (This
 isn't one monolithic list, by the way; it's the small bodies of a
 couple of small scheme functions that get evaluated over and over. So
 the setup and teardown happens a lot.) I don't have very good
 intuition yet about what should get garbage-collected and what should
 get kept in such situations, and in fact I'm kind of in the same boat
 again: the test case now runs much better, but it still leaks memory,
 and I am again stumped as to why. Could I see something useful by
 examining ghc core? I haven't looked at that yet, no idea what to look
 for...

 Uwe
 ___

mapM_ might be useful to you. I know there are cases where mapM leaks
memory but mapM_ doesn't, basically because mapM_ throws away all of
the intermediate results immediately. You might want to condition on
nullness of the list and then mapM_ your function over the init of the
list and then just return the function on the last element of the
list.

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


Re: [Haskell-cafe] How to pretty print code efficiently

2009-07-03 Thread Alexander Dunlap
On Fri, Jul 3, 2009 at 6:45 PM, John Kynewho...@gmail.com wrote:
 Hi,

 Currently I'm pretty printing code by building arrays of strings and calling
 indent.  For example:

 instance JavaPrintableNamed AST.EnumeratedType where
    javaLinesNamed parentName (AST.EnumeratedType memberDefinitions) =
   [ public enum  ++ asJavaId(parentName)
   , {
   ] ++ memberCodeLines ++
   [ }
   , 
   ]
   where
  memberCodeLines = indent $ javaLines memberDefinitions

 The indent function takes a list of strings and adds an indent to the
 beginning of every line.

 I can imagine this to be very inefficient as it builds many strings and
 concatenates them.

 In Ruby, I might do the same thing like this:

 class EnumeratedType  JavaPrintableNamed
    def writeTo(writer)
   writer.print public enum 
       writer.puts self.asJavaId
   writer.puts {
   writer.indent do
          self.memberDefinitions.writeTo(writer)
  writer.puts
   end

 where above, the writer.indent takes care of the indent, and everything is
 appended to a stream, which doesn't seem so bad in terms of efficiency.

 I'm looking for a way to do something similar in Haskell.

 Anyone can give me a hand?

 Thanks

 -John


 ___

You may want to investigate the standard module
Text.PrettyPrint.HughesPJ, which contains a number of (I assume fairly
efficient) combinators for pretty printing.

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


Re: [Haskell-cafe] Monoid wants a (++) equivalent

2009-07-03 Thread Alexander Dunlap
On Fri, Jul 3, 2009 at 10:17 PM, Jason Dusekjason.du...@gmail.com wrote:
 2009/07/03 George Pollard por...@porg.es:
 This discussion points to a wider issue: at some stage we
 should look at pulling all the nice new stuff into Haskell
 prelude. I'm looking at you, Data.Foldable,Traversable.

 Also, throw out `map`. ;)

  What is the proper name for the operation on functions of a
  functor, anyway? The name `fmap` seems to driven by an analogy
  with `map`.

 --
 Jason Dusek
 ___

I think map would be the right name. IMO, what would be really nice
would be to rename fmap to map (and then fmap would become a
deprecated synonym for map), etc., and get rid of many of the special
cases for lists in the Prelude. The only backward compatibility
problem that has been brought up is monomorphism restriction stuff,
though.

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


Re: [Haskell-cafe] Monoid wants a (++) equivalent

2009-07-02 Thread Alexander Dunlap
On Wed, Jul 1, 2009 at 11:26 AM, Ross Patersonr...@soi.city.ac.uk wrote:
 On Wed, Jul 01, 2009 at 10:55:39AM -0700, Bryan O'Sullivan wrote:
 Okay, here's a tentative plan that will help to figure out the answer. I'll
 build a fiddled base package that rewires the Monoid class to have (++) be 
 the
 binary operator, and mappend as a synonym for it. I'll import the Monoid (++)
 into the Prelude. I'll see how much breaks. If that much builds smoothly, 
 I'll
 see how much of the rest of Hackage builds, both with and without this custom
 base package. I'll follow up here with the results, along with a suggestion 
 of
 how acceptable I think the observed level of breakage is.

 Generalizing (++) will break some Haskell 98 code, e.g.

  append = (++)

 I think that's a show-stopper.
 ___

Could we use some default rules to keep H98 code working? I don't know
much about defaulting, but

times = (*)

works fine and defaults to type Integer. Could we not do the same
thing with monoids, having monoids default to type []?

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


Re: [Haskell-cafe] Monoid wants a (++) equivalent

2009-07-02 Thread Alexander Dunlap
On Wed, Jul 1, 2009 at 10:11 PM, David Menendezd...@zednenem.com wrote:
 In Wed, Jul 1, 2009 at 3:38 PM, Thomas Schillingnomin...@googlemail.com 
 wrote:
 2009/7/1 David Leimbach leim...@gmail.com
 Just because the compiler can figure out what I mean because it has a great
 type system, I might not be able to figure out what I mean a year from now
 if I see ++ everywhere.

 Yep, had the same experience.  On the one hand, using monoids lets you
 delay some design decisions for later and lets you reuse more library
 code.  On the other hand, it sometimes makes it really hard to see
 what the code is actually doing--especially if you use more than one
 monoid.

 For this reason on of the first advanced features I implemented in the
 (yet unreleased) scion IDE library allows you to look up the
 instantiated type of an identifier.  Unfortunately, jumping to the
 definition (or documentation) of the monoid instance is a bit more
 difficult.  Haddock should allow documentation on instance
 declarations...

 I disagree. The solution is to not create instances when it isn't
 obvious what the instance does. That's why we have Sum and Prod in
 Data.Monoid instead of declaring instances directly for Int.

 With Monoid, I'd go further and say that you should not use mempty and
 mappend unless you are writing polymorphic code. If you are writing to
 a specific monoid instance, you should use a specific function.

 --
 Dave Menendez d...@zednenem.com
 http://www.eyrie.org/~zednenem/
 ___

I tend to disagree. I think that Haskell has seen a lot of syntax
bloat in the interest of monomorphism. We have List.append, Map.union,
Set.union, Sequence., etc., all with different notation, even though
these all denote the same operation: taking two of (whatever) and
combining them into one. With mappend, you know exactly what the
function is supposed to do: combine two things together, and it
doesn't matter what datatypes you're using, because that's always what
it means.

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


Re: [Haskell-cafe] golf, predicate check function for MonadPlus (was Re: How to read safely?)

2009-07-02 Thread Alexander Dunlap
On Thu, Jul 2, 2009 at 3:36 AM, Jon Fairbairnjon.fairba...@cl.cam.ac.uk wrote:
 Dan Doel dan.d...@gmail.com writes:

 There was talk of adding a readMaybe a while ago, but apparently it
 never happened.

 As it is, you can use reads, read s becomes:

     case reads s of
       [(a, rest)] | all isSpace rest - code using a
       _                              - error case

 which ensures that you have an unambiguous parse with only trailing
 whitespace. You can, of course, modify that if you don't care about
 ambiguity or trailing characters.

 I was wondering about a more algebraic way of writing that; here's a
 version (that doesn't care about ambiguity)

 readMaybe :: Read a = String - Maybe a
 readMaybe
    = join . fmap no_trailing_garbage . listToMaybe . reads
      where no_trailing_garbage = fmap fst . check (all isSpace . snd)

 check :: (MonadPlus m) = (a - Bool) - a - m a
 check p a
    | p a = return a
    | otherwise = mzero


 I tried Hoogling for a function like check, but couldn't find it. Surely
 there's one in a library somewhere? It looks useful to me. (I'm rather
 taken by way the check (all isSpace . snd) part reads)

 Monad.guard comes close but fails to get the cigar; in fact

 guard b == check (const b) ()

 So check is more general.


 Also, I don't see a singletonListToMaybe that one could use in place of
 listToMaybe to require unambiguity. Could do

 isSingleton [a] = True
 isSingleton _ = False

 and then use listToMaybe . join . check isSingleton -- aha! Another
 use for check!




  Jón


 [Footnote: I thought of writing guard == flip (check . const) () but
 then realised it was pointless]

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


You can use the Kleisli composition operator (=) to make it a little nicer.

singletonListToMaybe :: [a] - Maybe a
singletonListToMaybe [x] = Just x
singletonListToMaybe _ = Nothing

check :: MonadPlus m = (a - Bool) - a - m a
check p a
  | p a = return a
  | otherwise = mzero

readMaybe = fmap fst.check (all isSpace.snd) = singletonListToMaybe.reads

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


Re: [Haskell-cafe] How to declare a Typeless Function

2009-07-02 Thread Alexander Dunlap
swap :: Array (Int, Int) a - [Int] - Array (Int, Int) a

The lowercase a means that that type variable is polymorphic, i.e.
it can be any type.

Alex

On Thu, Jul 2, 2009 at 8:05 PM, Fernan Bolandofernanbola...@mailc.net wrote:
 Hi

 I have a function that swaps rows of an array of double

 swap :: Array (Int,Int) Double - [Int] - Array (Int,Int) Double

 I then create a function that swaps rows of arrays of Complex Double

 swap :: Array (Int, Int) (Complex Double) - [Int] - Array (Int, Int)
 (Complex Double)

 In reality the function swap does not care whether its working on a
 double or a complex number.
 how do I declare swap so that it will work whether it's a complex or a
 double array.

 I tried googling but I wasn't sure what to google.

 fernan
 --
 http://www.fernski.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] Monoid wants a (++) equivalent

2009-07-01 Thread Alexander Dunlap
On Tue, Jun 30, 2009 at 11:24 PM, Ketil Maldeke...@malde.org wrote:

 You know, this might be the right time to start expanding our
 vocabulary beyond seven bits.  Since we're likely to keep mappend
 around as an alias for some time, people would have a grace period to
 adjust.

 How about U+2295 (circle with plus inside it)?

 Or, if we would like to stick to the 8-bit subset to keep those 8859-1
 users happy, how about ¤ (funny circle over an x, U+00A4)

 -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


The major disadvantage of that is that those symbols are not on my
keyboard and thus are more of a pain to type, especially on the Linux
console where compose key is not available...

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


Re: [Haskell-cafe] Obscure weirdness

2009-06-20 Thread Alexander Dunlap
On Sat, Jun 20, 2009 at 8:29 AM, Andrew Coppin
andrewcop...@btinternet.com wrote:

 OK, so here's an interesting problem...

 I've been coding away all day, but now my program is doing something slightly 
 weird. For a specific input, it summarily terminates. The registered 
 exception handler does not fire. There is no output to stdout or stderr 
 indicating what the problem is. It just *stops* half way through the printout.

 Weirder: If I run it in GHCi, then GHCi itself terminates. (I didn't think 
 you could *do* that!)

 It's not as if my program is anything unusual. There are no unsafe functions. 
 No FFI. Nothing. Just regular high-level Haskell.

 Is this a known bug in GHC 6.10.1? Will upgrading fix it? (Obviously, it's 
 quite a lot of work to change GHC.) Suffice it to say that my program is 
 quite big and complicated; it worked fine when it was still small and simple. 
 ;-)


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

I think you'll need to provide a bit more detail about what you're
doing in order for anyone to have anything to go off of. If you can
link to the source, that would help, or even give a summary of what
you're trying to do.

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


Re: Re[2]: [Haskell-cafe] Re: Error message reform (was: Strange type error with associated type synonyms)

2009-05-27 Thread Alexander Dunlap
On Wed, May 27, 2009 at 3:24 PM, Bulat Ziganshin
bulat.zigans...@gmail.com wrote:
 Hello Max,

 Thursday, May 28, 2009, 2:14:19 AM, you wrote:

 I absolutely agree about expected/inferred. I always forget which is
 which, because I can figure both could apply to each.

 That's actually true for me too. When you say it like that, I remember
 times when I've had the same confusion.

 it's why i asked beginners. it seems that we all go through times
 when ghc errmsgs looks cryptic but then we start to live with it and
 forget the first period

 actually, i don't have much problems with errrmsgs now, but trying to
 grok how i interpret them i've found that i mainly use *position*
 part of message, it's enough for me most times :)


 --
 Best regards,
  Bulat                            mailto:bulat.zigans...@gmail.com


Hi,

I like the expected/inferred vocabulary. Maybe it comes from being a
native English speaker, but to me, it says this is what we expected
to get, but instead (through type inference), we got this type for
this term.

Of course, I've also been reading GHC error messages for a while, so
I've gotten used to understanding what they mean. When I was new, I
had more of a problem...but I'm not sure you can really eliminate
that. Everything takes practice. :)

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


[Haskell-cafe] Re: Extensible Exceptions and IO

2009-05-23 Thread Alexander Dunlap
On Sat, May 23, 2009 at 9:09 AM, Ian Lynagh ig...@earth.li wrote:
 On Sat, Apr 25, 2009 at 11:18:43AM -0700, Alexander Dunlap wrote:
 In the extensible exceptions paper[1], which I believe is the guide
 behind the current Control.Exception in GHC 6.10, a SomeIOException
 type is discussed so that it would be possible to use the nice
 interface for IOExceptions. Is this implemented anywhere? In the GHC
 libraries, all I see is the old interface just plugged into a simple
 wrapper, so you have to use guard . isDoesNotExistError (for example)
 with catchJust to catch a certain type of exception. If not, are there
 any plans to implement it?

 I'm not aware of anyone currently working on putting the various core
 libs' exceptions into a sensible hierarchy, but it would be great if
 someone was to do so!

 I'd suggest that the best way to do this would be initially a
 combination of discussions on the mailing list (if anything is
 non-obvious) and building a design (and, if appropriate, rationale) on a
 wiki page, and ending with a library submissions proposal once you have
 a design worked out:

 http://www.haskell.org/haskellwiki/Library_submissions


 Thanks
 Ian



I'm moving this from the GHC users' mailing list to the haskell-cafe
mailing list because I think the discussion probably involves the
entire Haskell community.

Hi all,

We have this new exception hierarchy in GHC base-4 and a lot of new
machinery for dealing with it. Other libraries also seem to be
springing up to provide alternative methods of dealing with these new
exceptions.

However, I have found that in most of my programming, the new
exception functionality cannot be used to its fullest extent because
the exceptions in the core libraries are not part of any sensible
tree of exceptions, even though having this giant exception tree
seems to be one of the premises of the new exception library.

For example, there is an ArithException type in Control.Exception
which records various arithmetic exceptions. However, there are two
problems: (1) in order to fit in with the extensible exceptions theme,
the type ought to be called SomeArithException and all of the types of
ArithExceptions ought to be sub-exceptions of it, and (2) to my
knowledge, this exception type doesn't seem to be thrown by anything
in the base libraries.

I think the biggest culprit is the IOException type, which also
happens to be probably the most commonly-used exception type, since
exceptions from IOException cannot really be anticipated and
prevented.

The current design of IOException is as follows. There is an abstract
type called IOException. This can be queried with functions like
isDoesNotExistError (which determines if the exception is because a
file did not exist). Furthermore, to make an IOException, one has to
use the mkIOError function, which takes a value of type IOErrorType,
which is again an abstract type. I believe the reason for the abstract
types is to allow implementations to extend the range of exceptions.
Unfortunately, this has even more problems. For example, the error
returned by using readFile on a directory cannot be determined using
any Haskell98 function, meaning that code that wants to detect this
error cannot be portable to compilers that don't have the new
InappropriateType IO exception.

The biggest problem with the current design of IOException, however,
is that it doesn't play very nicely with the main hierarchy. Like with
ArithExceptions, there should be a SomeIOException type.
http://www.haskell.org/~simonmar/papers/ext-exceptions.pdf, which was
the original paper on extensible exceptions, recommends having a class
for IOExceptions that would allow us to get standard information from
any specific IOException.

I asked the GHC-users mailing list about this and Ian Lynagh
recommended starting a discussion about how to put all of the core
library exceptions into a sensible hierarchy.

I think the goals here ought to be to make our new hierarchy as
backward-compatible as possible. In particular, since many programs
rely on the isWhateverError functionality, it would be nice to keep
these in place.

For IOExceptions, I think it would be nice to have a more
multi-layered hierarchy than just SomeIOException and its subtypes.
For example, I could see a hierarchy for IOExceptions looking
something like this:

SomeIOException
  - SomeCouldNotOpenException
- AlreadyExists, NoSuchThing, PermissionDenied, InappropriateType
  - SomeResourceException
- ResourceBusy, ResourceExhausted, ResourceVanished

etc.

I'm not all that familiar with the various exceptions and how they are
used, so I'm not really able to propose a complete hierarchy for all
the exceptions. I guess the purpose of this email was just to start
off a discussion about what our exception hierarchy ought to look
like.

Thanks for reading this (admittedly long) message.

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

Re: Re: [Haskell-cafe] Re: A problem with par and modules boundaries...

2009-05-23 Thread Alexander Dunlap
On Sat, May 23, 2009 at 11:34 AM, Max Rabkin max.rab...@gmail.com wrote:
 On Sat, May 23, 2009 at 7:31 PM, Mario Blažević mblaze...@stilo.com wrote:
 Does anybody know of a pragma or another way to make a function *non-strict* 
 even
 if it does always evaluate its argument? In other words, is there a way to
 selectively disable the strictness optimization?

 parallelize a b | False = (undefined, undefined)
                   | otherwise = a `par` (b `pseq` (a, b))

 might do, unless strictness analysis is smart enough to know that the
 False guard is always, well, False.

 --Max
 ___

GHC.Prim.lazy?

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


Re: [Haskell-cafe] Introducing Instances in GHC point releases

2009-05-21 Thread Alexander Dunlap
Since those types come out of the time library, and that library's
version *has* been bumped (I assume), couldn't you use Cabal to
condition on the version of the time library to determine whether or
not to have CPP set a -DTYPEABLE_IN_TIME flag, and then #ifdef out
your versions of the instances?

I suppose a nice compiler extension would be recessive instances
which would take effect only if they did not overlap with another
instance. Probably a lot of corner cases involving multiple recessive
instances to work out, though.

Alex

On Thu, May 21, 2009 at 2:53 PM, John Goerzen jgoer...@complete.org wrote:
 So this is annoying (CCing -cafe)

 I need NominalDiffTime and UTCTime to have Typeable instances.  In
 6.10.1, they didn't ship with them out of the box, so I added them.
 Apparently, in 6.10.3, they DO ship with those instances out of the box.

 Annoyingly, that means that my code breaks on 6.10.3.

 Even more annoyingly, __GLASGOW_HASKELL__ is still 610, so I can't even
 work around this via cpphs.  There appears to be no way to make code
 that requires those Typeable instances work with both 6.10.1 and 6.10.3.

 Yet another reason to avoid API incompatibilities in point releases.

 Does anybody have an idea on the best way to handle this?

 -- John

 Don Stewart wrote:
 convertible appears broken with 6.10.3. Any thoughts?

     Writing new package config file... done.
     Downloading convertible-1.0.1...
     Configuring convertible-1.0.1...
     Preprocessing library convertible-1.0.1...
     Preprocessing executables for convertible-1.0.1...
     Building convertible-1.0.1...
     [1 of 8] Compiling Data.Convertible.Base ( Data/Convertible/Base.hs, 
 dist/build/Data/Convertible/Base.o )
     [2 of 8] Compiling Data.Convertible.Utils ( Data/Convertible/Utils.hs, 
 dist/build/Data/Convertible/Utils.o )
     [3 of 8] Compiling Data.Convertible.Instances.Map ( 
 Data/Convertible/Instances/Map.hs, 
 dist/build/Data/Convertible/Instances/Map.o )
     [4 of 8] Compiling Data.Convertible.Instances.Num ( 
 Data/Convertible/Instances/Num.hs, 
 dist/build/Data/Convertible/Instances/Num.o )
     [5 of 8] Compiling Data.Convertible.Instances.C ( 
 Data/Convertible/Instances/C.hs, dist/build/Data/Convertible/Instances/C.o )
     [6 of 8] Compiling Data.Convertible.Instances.Time ( 
 Data/Convertible/Instances/Time.hs, 
 dist/build/Data/Convertible/Instances/Time.o )

     Data/Convertible/Instances/Time.hs:61:9:
         Duplicate instance declarations:
           instance Typeable NominalDiffTime
             -- Defined at Data/Convertible/Instances/Time.hs:61:9-32
           instance Typeable NominalDiffTime
             -- Defined in time-1.1.3:Data.Time.Clock.UTC

     Data/Convertible/Instances/Time.hs:64:9:
         Duplicate instance declarations:
           instance Typeable UTCTime
             -- Defined at Data/Convertible/Instances/Time.hs:64:9-24
           instance Typeable UTCTime
             -- Defined in time-1.1.3:Data.Time.Clock.UTC
     cabal: Error: some packages failed to install:
     HDBC-2.1.0 depends on convertible-1.0.1 which failed to install.
     convertible-1.0.1 failed during the building phase. The exception was:



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

2009-05-21 Thread Alexander Dunlap
I believe you need to capitalize it correctly: HUnit.

Alex

On Thu, May 21, 2009 at 8:52 PM, Vasili I. Galchin vigalc...@gmail.com wrote:
 my bad ... what about:

 vigalc...@ubuntu:~/FTP/Haskell/Swish-0.2.1$ cabal configure
 Configuring swish-0.2.1...
 cabal: At least the following dependencies are missing:
 hunit -any


 On Thu, May 21, 2009 at 6:20 PM, Don Stewart d...@galois.com wrote:

 vigalchin:
  Hello,
 
      I have some code with several test cases that use HUnit. I added
  hunit as
  one of my cabal dependencies but cabal complained with:
 
  Setup: At least the following dependencies are missing:
  hutil -any
  ^

 Typo.

 -- Don


 ___
 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] Building 'text-icu-0.1' on Windows

2009-05-16 Thread Alexander Dunlap
On Thu, May 14, 2009 at 10:25 AM, Bryan O'Sullivan b...@serpentine.com wrote:
 On Thu, May 14, 2009 at 10:18 AM, Bryan O'Sullivan b...@serpentine.com
 wrote:

 If one of you has the time to dig into this and send a patch that corrects
 the problem, I'd welcome the help. As I'm sure you can tell, I developed
 text-icu on Unix, and I don't have regular enough Windows access to make
 debugging this a quick and easy matter.

 By the way, if you run into problems building or using text or text-icu,
 please file a ticket here: http://trac.haskell.org/text/newticket


Hi,

I've attached a patch that fixes the build on Windows. It also doesn't
seem to break the build on my Linux box. However, the patch basically
consists of removing an #include statement and removing some library
dependencies (which for some reason don't exist in the Windows
distribution of ICU), so I don't know if it would break something
else. The library compiles without warnings with the patch applied,
though. Maybe Serge could test the patch on his machine?

Thanks,
Alex


fix-windows-build.dpatch
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Data.FiniteMap deprecrated

2009-05-16 Thread Alexander Dunlap
You need to include the containers package in your cabal file.

Alex

On Sat, May 16, 2009 at 4:44 PM, Vasili I. Galchin vigalc...@gmail.com wrote:
 Yevgeni,

  I am specifying base as a Cabal dependency ...  dumb question ... I
 have forgotten whether I need to import Data.Map also?

 Vasili

 On Sat, May 16, 2009 at 1:05 AM, Eugene Kirpichov ekirpic...@gmail.com
 wrote:

 It's Data.Map. It's in the base package.

 2009/5/16 Vasili I. Galchin vigalc...@gmail.com:
  Hello,
 
 
  http://hackage.haskell.org/cgi-bin/hackage-scripts/package/FiniteMap
  ... since this is deprecated what is the orthodox way to implement
  finite
  map??
 
  Thanks,
 
  Vasili
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 



 --
 Eugene Kirpichov
 Web IR developer, market.yandex.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.FiniteMap deprecrated

2009-05-16 Thread Alexander Dunlap
You need to import Data.Map in any file you use Map in.

Which version of Parsec are you using? Versions before 3.0.0 do not
have a module called Text.Parsec, the module is
Text.ParserCombinators.Parsec (or something like that).

Alex

On Sat, May 16, 2009 at 5:03 PM, Vasili I. Galchin vigalc...@gmail.com wrote:
 yeah  I do  ghc can't find the Map constructor ..

 also in another module Parsec is being used ... I have parsec as a dependecy
 in my cabal file and I also have an import Text.Parsec but ghc could not
 find module Text.Parsec. ???

 Thanks, Vasili

 On Sat, May 16, 2009 at 6:57 PM, Alexander Dunlap
 alexander.dun...@gmail.com wrote:

 You need to include the containers package in your cabal file.

 Alex

 On Sat, May 16, 2009 at 4:44 PM, Vasili I. Galchin vigalc...@gmail.com
 wrote:
  Yevgeni,
 
   I am specifying base as a Cabal dependency ...  dumb question ...
  I
  have forgotten whether I need to import Data.Map also?
 
  Vasili
 
  On Sat, May 16, 2009 at 1:05 AM, Eugene Kirpichov ekirpic...@gmail.com
  wrote:
 
  It's Data.Map. It's in the base package.
 
  2009/5/16 Vasili I. Galchin vigalc...@gmail.com:
   Hello,
  
  
   http://hackage.haskell.org/cgi-bin/hackage-scripts/package/FiniteMap
   ... since this is deprecated what is the orthodox way to implement
   finite
   map??
  
   Thanks,
  
   Vasili
  
   ___
   Haskell-Cafe mailing list
   Haskell-Cafe@haskell.org
   http://www.haskell.org/mailman/listinfo/haskell-cafe
  
  
 
 
 
  --
  Eugene Kirpichov
  Web IR developer, market.yandex.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] Building 'text-icu-0.1' on Windows

2009-05-13 Thread Alexander Dunlap
On Wed, May 13, 2009 at 12:54 AM, Serge LE HUITOUZE
slehuito...@telisma.com wrote:
 Hi there,

 I fail to build text-icu-0.1 on Windows, and would appreciate some help...
 Thanks in advance!

 Let me describe what I've done so for, and what results I got:

 First, I got a version of ICU on my machine, specifically unzipping the
 file icu4c-4_0_1-Win32-msvc8.zip from
 http://icu-project.org/download/4.0.html.
 This made me having ICU stuff at location C:\HaskellStuff\icu\icu, as
 witnessed below:

 C:\HaskellStuff\icu\icudir
  30/04/2009  16:08    REP  .
  30/04/2009  16:08    REP  ..
  30/04/2009  16:51    REP  bin
  30/04/2009  16:08    REP  include
  30/04/2009  16:36    REP  lib
  14/01/2009  22:48 2 032 license.html

 After downloading and untaring text-icu-0.1, I tried to configure, typing
 in:

 C:\HaskellStuff\pkg\text-icu-0.1runhaskell Setup configure
  Configuring text-icu-0.1...
  Setup: Missing dependencies on foreign libraries:
  * Missing C libraries: icui18n, icuuc, icudata
  This problem can usually be solved by installing the system packages that
  provide these libraries (you may need the -dev versions). If the
 libraries
  are already installed but in a non-standard location then you can use the
  flags --extra-include-dirs= and --extra-lib-dirs= to specify where they
 are.

 OK, let's restart with appropriate values for said flags!

 C:\HaskellStuff\pkg\text-icu-0.1runhaskell Setup configure
    --extra-include-dirs=C:\HaskellStuff\icu\icu\include
    --extra-lib-dirs=C:\HaskellStuff\icu\icu\lib
  Configuring text-icu-0.1...

 And then proceed with the building per se:

 C:\HaskellStuff\pkg\text-icu-0.1runhaskell Setup build
  Preprocessing library text-icu-0.1...
  In file included from
 C:/HaskellStuff/icu/icu/include/unicode/umachine.h:47,
   from
 C:/HaskellStuff/icu/icu/include/unicode/utypes.h:36,
   from Data\Text\ICU\Error.hsc:148:
  C:/HaskellStuff/icu/icu/include/unicode/pwin32.h:120:
    error: redefinition of typedef 'int8_t'
  C:/ghc/ghc-6.10.1/include/mingw/stdint.h:27:
    error: previous declaration of 'int8_t' was here
  ...
  ... (a bunch of similar messages for other type aliases, e.g. 'uint8_t')
  ...
  compiling dist\build\Data\Text\ICU\Error_hsc_make.c failed
  command was: C:\ghc\ghc-6.10.1\gcc.exe -c -BC:\ghc\ghc-6.10.1\gcc-lib
  -IC:\ghc\ghc-6.10.1\include\mingw
 -D__GLASGOW_HASKELL__=610
  -IC:\HaskellStuff\icu\icu\include
  -IC:\ghc\ghc-6.10.1\bytestring-0.9.1.4\include
  -IC:\ghc\ghc-6.10.1\base-4.0.0.0\include
  -IC:\ghc\ghc-6.10.1/include
  -IPAPI_INCLUDE_DIR
 dist\build\Data\Text\ICU\Error_hsc_make.c
  -o dist\build\Data\Text\ICU\Error_hsc_make.o
 
  C:\HaskellStuff\pkg\text-icu-0.1

 The mingw/stdint.h file contains a series of lines of this style:
 
  typedef signed char int8_t;

 Whereas, the unicode/pwin32.h file contains contains stuff like:
 
  /* Define whether inttypes.h is available */
  #ifndef U_HAVE_INTTYPES_H
  #define U_HAVE_INTTYPES_H 0
  #endif
  ...
 
  /* Determines whether specific types are available */
  #ifndef U_HAVE_INT8_T
  #define U_HAVE_INT8_T U_HAVE_INTTYPES_H
  #endif
  ...
 
  /* If your platform does not have the inttypes.h header, you may
     need to edit the typedefs below. */
  #if U_HAVE_INTTYPES_H
  #include inttypes.h
  #else /* U_HAVE_INTTYPES_H */
 
  #if ! U_HAVE_INT8_T
  typedef signed char int8_t;
  #endif
  ...
  #endif

 So, do I need to explicitely change the icu include file?
 And in which way?

 Any other solution/suggestion?

 Best regards.

 --Serge


This isn't really helpful, but I received similar errors when trying
to build icu-text on Windows. It seemed like the problem was that
GHC's headers defined some of the symbols that were also defined in
ICU...I don't know how to fix this though.

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


Re: [Haskell-cafe] Main function error

2009-05-12 Thread Alexander Dunlap
On Tue, May 12, 2009 at 9:59 AM, applebiz89 applebi...@hotmail.com wrote:

 I have compiled each function independently and they have compiled the only
 problem is the main function..

 I keep getting the error 'films not defined' and I am not sure why

 [code]

 type Title = String
 type Director = String
 type Year = Int
 type Fan = String

 data Film = Film Title Director Year [Fan] deriving Show

 -- List of films

 testDatabase :: [Film]
 testDatabase = [ (Film Casino Royale Martin Campbell 2006 [Garry,
 Dave, Zoe])]

 -- Function

 filmsInGivenYear :: Year - [Film] - [String]
 filmsInGivenYear year' films = [ title | (Film title director year fans) -
 films, year == year']

 doFilmsInGivenYear :: [Film] - IO ()
 doFilmsInGivenYear films  = do putStrLn which year?
                               text - getLine
                               let year' = read text :: Int
                               let answer = filmsInGivenYear year' films
                               print answer

 main :: IO ()
 main = do
         doFilmsInGivenYear films
         main

 [/code]

 if the other functions are compiling without this error im not sure as to
 why the main function does not compile because of the films...any light on
 this?

 Thanks

When you say 'doFilmsInGivenYear films', where does the variable
'films' come from? It's not defined anywhere in your program. That's
what the compiler is complaining about.

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


Re: [Haskell-cafe] Just 3 = (1+)?

2009-05-09 Thread Alexander Dunlap
On Sat, May 9, 2009 at 12:31 PM, michael rice nowg...@yahoo.com wrote:
 Why doesn't this work?

 Michael

 

 data Maybe a = Nothing | Just a

 instance Monad Maybe where
     return = Just
     fail   = Nothing
     Nothing  = f = Nothing
     (Just x) = f = f x

 instance MonadPlus Maybe where
     mzero = Nothing
     Nothing `mplus` x = x
     x `mplus` _   = x

 

 [mich...@localhost ~]$ ghci
 GHCi, version 6.10.1: http://www.haskell.org/ghc/  :? for help
 Loading package ghc-prim ... linking ... done.
 Loading package integer ... linking ... done.
 Loading package base ... linking ... done.
 Prelude Just 3 = (1+)

 interactive:1:0:
     No instance for (Num (Maybe b))
   arising from a use of `it' at interactive:1:0-14
     Possible fix: add an instance declaration for (Num (Maybe b))
     In the first argument of `print', namely `it'
     In a stmt of a 'do' expression: print it
 Prelude


The type of (=) is

(=) :: m a - (a - m b) - m b

For the Maybe monad, that specializes to

(=) :: Maybe a - (a - Maybe b) - Maybe b

But when you say

Just 3 = (+1)

this desugars to

(=) (Just 3) (\x - x + 1)

but the second argument to (=) that you have given has the type (\x
- x + 1) :: Num a = a - a, whereas it needs to return a type of
Maybe a to fit the type signature.

What you probably want is

Just 3 = (Just . (+1))

so the second function returns a Maybe value. A nicer way of writing this is

fmap (+1) (Just 3), which uses the Functor class. Intuitively, the
fmap function applies a function to the inside of a container. All
monads can be defined as Functors as well; all Monads in the standard
libraries have their functor instances defined.

Hope that helps you.

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


Re: [Haskell-cafe] Re: ANNOUNCE: Utrecht Haskell Compiler (UHC) -- first release

2009-04-21 Thread Alexander Dunlap
On Tue, Apr 21, 2009 at 8:34 PM, Richard O'Keefe o...@cs.otago.ac.nz wrote:

 On 21 Apr 2009, at 7:39 pm, Jason Dagit wrote:

 Not really.  Obviously some programs use the feature, but let us
 restrict to interesting programs that have been shared with the world
 and have some potential to receive maintenance.

 Why?

 You are, in effect, saying that my code has no value at all.
 You are saying that code written by students has no value at all.
 Why do you think that only code that is shared with the world
 has some potential to receive maintenance?

 By the way, not all publicly available code is in Hackage.
 The hbc release that's on my SPARC -- and thankful I've been for
 it, the grief GHC has given me there -- has at least one use of
 an n+k pattern that I know of, and more in a specification comment.

  From these programs
 we can do a sampling.  While I'm not a statistics expert, my
 understanding is the main problem with using hackage packages is a bit
 of selection bias.

 I can see no reason to assume that it's only a bit.
 Maybe it's a bit.  Maybe it's a very great deal.
 It would be interesting to investigate this, but the only way
 you can investigate it is to examine a lot of code that
 _isn't_ there.

  I bet the selection bias isn't even that bad for
 this statistical test due to the nature of programming style
 diversity.  Maybe someone with a stronger stats background could
 comment.

 I have a statistics degree.  I don't know if that's strong enough
 for you.  It's strong enough that I assume selection bias until I
 see evidence otherwise.

 I think that would give us an exhaustive collection of haskell code,
 but I assert we don't need that.  Biologists don't need a DNA sample
 from every organism to draw conclusions about the genetics of a
 species.

 It depends on what _kind_ of conclusion they want to draw.
 If they want to show that some feature _is_ present, a sample
 will do.  If they want to show that it's absent or rare, then
 they need a much bigger sample.

  Scientists work with incomplete data and draw sound
 conclusions in spite of that.  The tools they use to do so are known
 as statistics.

 Yes, I know.  That's why I get cross when people suggest silly
 things like trawling through Hackage to demonstrate that nobody
 is using n+k patterns.  Where's the statistics in that?  Where are
 the estimates of natural variation?

 Note: I do not assert that the use of n_k patterns is rare.
 Here's _all_ that I assert about n+k patterns:
 (1) they are part of Haskell 98
 (2) I believe they make programs more readable
 (3) I use them
 (4) they are no worse than certain features proposed for
    addition to Haskell'.

 Okay, then prove n+k patterns are not rare in the publicly available
 sources.


 Why the X should I?  I do not claim that they are common
 IN THE PUBLICLY AVAILABLE SOURCES, I have NEVER claimed that,
 and I don't even CARE whether they are rare in the publicly
 available sources or not.

 Because they make programs more readable, n+k patterns
 probably *should* be moderately common in the publicly available
 sources, but I have no idea whether they are or not.

 It *is* true that things that *are* used in the commonly
 available sources should continue to be supported in order
 to preserve the value of those commonly available sources.
 It is *not* true that things that are *not* used in the
 commonly available sources are therefore of no value and
 safely to be discarded.

 That's the challenge I was trying to make in my first email.

 It's a challenge to the irrelevant.

 Let's consider three versions of naive Fibonacci.

 fibA :: (Integral a, Integral b) = a - b

 fibA 0 = 1
 fibA 1 = 1
 fibA (n+2) = fibA (n+1) + fibA n

 Simple, readable, Haskell 98.

 pred2 :: (Integral a) = a - Maybe a
 pred2 n = if n = 2 then Just (n-2) else Nothing

 fibB :: (Integral a, Integral b) = a - b

 fibB 0 = 1
 fibB 1 = 1
 fibB x | Just n - pred2 x = fibB (n+1) + fibB n

 Uses a pattern guard, implemented in GHC.

 Pattern guards are neat.  I like them a lot.  They make sense.
 But it's impossible for me to see fibB as more readable than
 fibA.

 While pattern guards come _close_ to offering a replacement
 for n+k patterns, they don't quite.  If I had

 f x (n+1)
  | p x = ...
  | q x = ...

 I would have to write the pattern guard twice as

 f x n'
  | Just n - pred1 n', p x = ...
  | Just n - pred1 n', q x = ...

 That doesn't seem like an advantage, somehow.

 Now for the third alternative.
 The view proposal in the Haskell' wiki and the views implemented
 in GHC are different.  In fact the view proposal document goes to
 some trouble to show how views can replace n+k patterns, so I
 suppose I don't need to review that.  Here's what it looks like
 using GHC syntax.  (I can't make ghc 6.8.3 accept this;
 ghc --supported-languages does not list ViewPatterns.  So this is
 UNTESTED CODE!)

 data Integral a = Nat2 a = Succ2 a | One2 | Zero2

 nat2 :: Integral a = a - Nat2 a

 nat2 n | 

Re: [Haskell-cafe] ANNOUNCE: Runge-Kutta library -- solve ODEs

2009-04-20 Thread Alexander Dunlap
It would also be nice if you could plug it into the hierarchical
module system somewhere, perhaps renaming the module to
Data.Algorithm.RungeKutta or Numeric.RungeKutta or
Math.RungeKutta. This is pretty much the standard practice now, I
think.

Alex

On Sun, Apr 19, 2009 at 4:04 PM, Uwe Hollerbach uhollerb...@gmail.com wrote:
 Damn, I never thought of that. Sorry! Guess I've only been
 haskell-hacking on my little old iMac...

 A new version is attached, with the version number bumped up by 0.0.1
 and rungekutta.hs renamed to RungeKutta.hs. Hopefully it should work
 out-of-the-box now. Off to patch my repository...

 Uwe

 On 4/19/09, Alexey Khudyakov alexey.sklad...@gmail.com wrote:
 I have so far only tested it with ghc 6.8.3 on MacOS 10.3.9 (powerPC),
 but I know of no reason why it wouldn't work with other versions and
 OSs.

 It breaks on Linux (and all unices) because name of file in tarball is
 'rungekutta.hs' not
 'RungeKutta.hs' as required. In other words: god blame
 case-insensitive file systems.

 After renaming everything works just fine.
 ___
 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] Infix tuple comma query (,)

2009-04-06 Thread Alexander Dunlap
On Mon, Apr 6, 2009 at 8:53 AM, Paul Keir pk...@dcs.gla.ac.uk wrote:
 module Main where



 data (:%^) a b = a :%^ b    deriving (Show)



 main = do

   print $ 18 :%^ (Just 99)

   print $ (,) 9 10

   print $ 9 , 10



 The last line in the code above causes a compile error.

 Why does infix use of the comma (tuple constructor?) function fail without
 brackets?



 Thanks,

 Paul


When I want a lighter syntax for pairs (when doing a long list of
them, e.g.), I often define

() :: a - b - (a,b)
a  b = (a,b)

and then you can indeed write

print $ 1  2

(assuming you get precedence right).

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


Re: [Haskell-cafe] Use unsafePerformIO to catch Exception?

2009-03-26 Thread Alexander Dunlap
On Thu, Mar 26, 2009 at 5:23 PM, wren ng thornton w...@freegeek.org wrote:
 Jules Bean wrote:

 wren ng thornton wrote:
  I have long been disappointed by a number of `error`s which shouldn't 
  be. For example, the fact that `head` and `div` are not total strikes  me
  as a (solvable) weakness of type checking, rather than things that  should
  occur as programmer errors/exceptions at runtime. The use of  `error` in
  these cases muddies the waters and leads to a laissez-faire  attitude 
  about
  when it's acceptable to throw one's hands up in despair  and use `error`
  rather than writing a better function.

 head uses error in precisely the correct, intended fashion.

 head has a precondition (only call on non-empty lists)

 And that is *exactly* my complaint: the precondition is not verified by the
 compiler. Therefore it does not exist in the semantic system, which is why
 the error screws up semantic analysis.

 The type of head should not be [a] - a + Error, it should be (a:[a]) - a.
 With the latter type the compiler can ensure the precondition will be proved
 before calling head, thus eliminating erroneous calls.

 It's a static error, detectable statically, and yet it's deferred to the
 runtime. I'd much rather the compiler catch my errors than needing to create
 an extensive debugging suite and running it after compilation. Is this not
 the promise of purity?

Ultimately, it's not detectable statically, is it? Consider

import Control.Applicative

main = do
  f - lines $ readFile foobar
  print (head (head f))

You can't know whether or not head will crash until runtime.

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


Re: [Haskell-cafe] Data.Binary, Data.Text and errors

2009-03-21 Thread Alexander Dunlap
On Sun, Mar 15, 2009 at 9:13 PM, Bryan O'Sullivan b...@serpentine.com wrote:
 On Sun, Mar 15, 2009 at 8:40 PM, Alexander Dunlap
 alexander.dun...@gmail.com wrote:

 I have noticed that in both Data.Binary and Data.Text (which is still
 experimental, but still), the decode functions can be undefined
 (i.e. bottom) if they encounter malformed input.

 For decoding Unicode, it's typical to provide a flexible API that can do one
 of the following on a bad encoding:

 Substitute a character
 Skip it
 Return the partial decode
 Throw an exception

 I just haven't gotten there yet.


Thanks! I guess we'll see how this comes together.

Does anyone know about error handling options in Data.Binary? Are
there plans to add an error handling mechanism?

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


Re: [Haskell-cafe] Editing Haskell wiki pages

2009-03-20 Thread Alexander Dunlap
On Fri, Mar 20, 2009 at 3:24 AM, Colin Paul Adams
co...@colina.demon.co.uk wrote:
 Bulat == Bulat Ziganshin bulat.zigans...@gmail.com writes:

    Bulat Hello Colin,
    Bulat Friday, March 20, 2009, 9:18:59 AM, you wrote:

 How am I supposed to edit a page on the Haskell wiki?

     If I click on an Edit this page link, then Firefox prompts me
     to choose a tool to open an application/x-external-editor. When
     i just

    Bulat it should be a problem with your config, i just tried with
    Bulat ff 3.0.7/win32 - it edits fine. nothing was specially
    Bulat configured for this behaviour

 I haven't configured anything special either.
 ff 3.0.7/Linux x64


Go to your preferences page. Under the Editing tab, the field Use
external editor by default is probably checked. Uncheck it, and you
will be able to edit the pages directly in Firefox.

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


Re: [Haskell-cafe] Editing Haskell wiki pages

2009-03-20 Thread Alexander Dunlap
On Fri, Mar 20, 2009 at 7:31 AM, Colin Paul Adams
co...@colina.demon.co.uk wrote:
 Alexander == Alexander Dunlap alexander.dun...@gmail.com writes:

    Alexander On Fri, Mar 20, 2009 at 3:24 AM, Colin Paul Adams
    Alexander co...@colina.demon.co.uk wrote:
     Bulat == Bulat Ziganshin bulat.zigans...@gmail.com
     writes:
    
        Bulat Hello Colin,
        Bulat Friday, March 20, 2009, 9:18:59 AM, you wrote:
    
     How am I supposed to edit a page on the Haskell wiki?
    
         If I click on an Edit this page link, then Firefox
     prompts me     to choose a tool to open an
     application/x-external-editor. When     i just
    
        Bulat it should be a problem with your config, i just tried
     with    Bulat ff 3.0.7/win32 - it edits fine. nothing was
     specially    Bulat configured for this behaviour
    
     I haven't configured anything special either.  ff 3.0.7/Linux
     x64
    

 Go to your preferences page. Under the Editing tab, the field Use
    Alexander external editor by default is probably
    Alexander checked. Uncheck it, and you will be able to edit the
    Alexander pages directly in Firefox.

 What Editing tab?
 --
 Colin Adams
 Preston Lancashire


It's on the left-hand side of the page, at least on my screen. I guess
it doesn't really look like a tab, but there's a link that says
Editing on the Preferences page.

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


Re: [Haskell-cafe] Editing Haskell wiki pages

2009-03-20 Thread Alexander Dunlap
On Fri, Mar 20, 2009 at 8:07 AM, Colin Paul Adams
co...@colina.demon.co.uk wrote:
 Alexander == Alexander Dunlap alexander.dun...@gmail.com writes:


     What Editing tab?  -- Colin Adams Preston Lancashire
    

 It's on the left-hand side of the page, at least on my screen. I guess
    Alexander it doesn't really look like a tab, but there's a link
    Alexander that says Editing on the Preferences page.

 Which preferences page - there are lots of them.
 But wherever I look, I can't see it.
 --
 Colin Adams
 Preston Lancashire


http://haskell.org/haskellwiki/Special:Preferences

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


[Haskell-cafe] Data.Binary, Data.Text and errors

2009-03-15 Thread Alexander Dunlap
Hi all,

I have noticed that in both Data.Binary and Data.Text (which is still
experimental, but still), the decode functions can be undefined
(i.e. bottom) if they encounter malformed input.

What is the preferred way to use these functions in a safe way? For
example, if one writes data to a disk using Data.Binary and wants to
read it back in at a later date, how can one ensure that it is valid
so that Data.Binary does not hit an error? Or do you just have to
catch the exception in the IO Monad?

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


Re: [Haskell-cafe] Natural Numbers: Best implementation?

2009-03-12 Thread Alexander Dunlap
2009/3/12 Mark Spezzano mark.spezz...@chariot.net.au:
 Hi,



 I was wondering what the best way to implement Natural number would be. Is
 there a package which already does this?



 Here are some options:



 1.  Don’t bother. Just use Integer.

 2.  Use the type

 data Natural = Zero | Succ !Natural

 3.  Use the following definition taken from the Gentle Introduction to
 Haskell 98

 newtype Natural = MakeNatural Integer

 toNatural ::Integer- Integer

 toNatural x | x  0 = error “Can’t create negative naturals!”

      | otherwise = MakeNatural x

 fromNatural :: Natural - Integer

 fromNatural (MakeNatural i) = i



 and then...



 instance Num Natural where

   fromInteger = toNAtural

   x + y   = toNatural (fromNatural x + fromNatural y)

   x – y   = etc..

   x * y   = etc...



 Which method is best? So far, I’ve been picking option #1 – just leaving
 things as they are and using Integer to keep things simple.



 I’ve got that feeling that [2] would be fast and [3] would be slow. Comment
 appreciated on the merits of each.



 Cheers,



 Mark Spezzano


I would tend to use option (1) unless there's a compelling reason not
to. Since naturals aren't closed under subtraction, you would in
practice probably have just as many non-total functions as you would
with the regular Int{,eger} type. Also, a lot of functions just take
Integers so it would be more of a pain to use.

In terms of speed, I think that [3] would be reasonably fast (unless
you do a ton of subtraction with bounds-checking) and [2] would
probably be quite slow, because you don't get the speed-boost from
doing computations right on the processor.

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


Re: [Haskell-cafe] bytestring vs. uvector

2009-03-09 Thread Alexander Dunlap
On Mon, Mar 9, 2009 at 3:12 AM, Henning Thielemann
lemm...@henning-thielemann.de wrote:

 On Mon, 9 Mar 2009, Claus Reinke wrote:

 Given the close relationship between uvector and vector, it would
 be very helpful if both package descriptions on hackage could point to a
 common haskell wiki page, starting out with the text
 and link above, plus a link to the stream fusion paper (I hadn't been
 aware that vector incorporates the recycling work, and had often wondered
 about the precise relationship between those
 two packages). Apart from saving others from similar confusion,
 that would also provide a place to record experience with those two
 alternatives.

 I have at least started a page which mentions the existing alternatives:
   http://www.haskell.org/haskellwiki/Storable_Vector
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


Thanks for all of the responses!

So let me see if my summary is accurate here:

- ByteString is for just that: strings of bytes, generally read off of
a disk. The Char8 version just interprets the Word8s as Chars but
doesn't do anything special with that.
- Data.Text/text library is a higher-level library that deals with
text, abstracting over Unicode details and treating each element as
a potentially-multibye character.
- utf8-string is a wrapper over ByteString that interprets the bytes
in the bytestring as potentially-multibye unicode characters.

- uvector, storablevector and vector are all designed for dealing with
arrays. They *can* be used for characters/word8s but are not
specialized for that purpose, do not deal with Unicode at all, and are
probably worse at it. They are better for dealing with things that you
would generally use arrays for.

If that seems accurate, I'll put it on the wiki.

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


Re: [Haskell-cafe] Re: derive Drift - some help please

2009-03-08 Thread Alexander Dunlap
What problems are you encountering?

Alex

On Sun, Mar 8, 2009 at 11:58 AM, G?uenther Schmidt red...@fedoms.com wrote:
 Hi Sterling,

 sry, but I can't get it to work.

 Günther

 Sterling Clover schrieb:

 You shouldn't need any extra tools for this. A combination of the
 StandaloneDeriving and DeriveDataTypeable extensions in GHC should suffice.

 Cheers,
 S.

 On Sun, Mar 8, 2009 at 10:30 AM, Gü?nther Schmidt gue.schm...@web.de
 mailto:gue.schm...@web.de wrote:

    Hi,

    I need to derive Data, Typeable for Data.Time.LocalTime. I had hoped
    to use either derive or DrIFT to generate the instance declarations
    for it.

    I tried to understand the respective user manuals but it's still all
    Greek to me.

    Someone please help!

    Günther

    ___
    Haskell-Cafe mailing list
    haskell-c...@haskell.org mailto: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

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


[Haskell-cafe] Re: derive Drift - some help please

2009-03-08 Thread Alexander Dunlap
Well you can do

 deriving instance Typeable LocalType

etc. if you enable the DeriveDataTypeable and StandaloneDeriving
extensions. You will get other error messages for missing instances;
just keep adding

 deriving instance Typeable Day

etc. Eventually, you will need to implement an instance by hand for
Pico, because Pico's data constructors are not exported from
Data.Fixed. I'm not very familiar with Data and Typeable so I can't
help you there, but you can probably look at some existing instances
for help.

Hope that's useful for you.

Alex

On Sun, Mar 8, 2009 at 12:40 PM, Gü?nther Schmidt gue.schm...@web.de wrote:
 Hi Alexander,


 well I have this:

 newtype AdmissionDate = AdmDt LocalTime
        deriving (Data,Typeable ..)

 at least that's where I wonna get.

 I don't know how to create the proper instance declarations though for
 LocalTime.

 AdmissionDate is an element of a larger data structure, this data structure
 for instance also has a

 newtype DischargeDate = DchrgDt LocalTime
        deriving (Data,Typeable ...)

 With my haskell work so far I was blessedly free of the need for deriving.
 Until now ...

 Günther


 Alexander Dunlap schrieb:

 What problems are you encountering?

 Alex

 On Sun, Mar 8, 2009 at 11:58 AM, G?uenther Schmidt red...@fedoms.com
 wrote:

 Hi Sterling,

 sry, but I can't get it to work.

 Günther

 Sterling Clover schrieb:

 You shouldn't need any extra tools for this. A combination of the
 StandaloneDeriving and DeriveDataTypeable extensions in GHC should
 suffice.

 Cheers,
 S.

 On Sun, Mar 8, 2009 at 10:30 AM, Gü?nther Schmidt gue.schm...@web.de
 mailto:gue.schm...@web.de wrote:

   Hi,

   I need to derive Data, Typeable for Data.Time.LocalTime. I had hoped
   to use either derive or DrIFT to generate the instance declarations
   for it.

   I tried to understand the respective user manuals but it's still all
   Greek to me.

   Someone please help!

   Günther

   ___
   Haskell-Cafe mailing list
   Haskell-Cafe@haskell.org mailto: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




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


[Haskell-cafe] bytestring vs. uvector

2009-03-07 Thread Alexander Dunlap
Hi all,

For a while now, we have had Data.ByteString[.Lazy][.Char8] for our
fast strings. Now we also have Data.Text, which does the same for
Unicode. These seem to be the standard for dealing with lists of bytes
and characters.

Now we also have the storablevector, uvector, and vector packages.
These seem to be also useful for unpacked data, *including* Char and
Word8 values.

What is the difference between bytestring and these new fast array
libraries? Are the latter just generalizations of the former?

Thanks for any insight anyone can give on this.

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


Re: [Haskell-cafe] environment variables for runghc?

2009-03-03 Thread Alexander Dunlap
I doubt there's an env variable, but you could do

$ alias ghc='ghc -Wall'

Alex

On Tue, Mar 3, 2009 at 7:07 PM, Erik de Castro Lopo
mle...@mega-nerd.com wrote:
 Hi all,

 Is there some environment variable I can set so that runghc can
 be told to always use -Wall?

 Cheers,
 Erik
 --
 -
 Erik de Castro Lopo
 -
 ... a discussion of C++'s strengths and flaws always sounds
 like an argument about whether one should face north or east
 when one is sacrificing one's goat to the rain god.
 -- Thant Tessman
 ___
 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] Practise of hiding contsructors and serialization

2009-02-22 Thread Alexander Dunlap
On Sun, Feb 22, 2009 at 5:23 PM, Marc Weber marco-owe...@gmx.de wrote:
I usually use Data.Binary for serialization.
 Sure. But you can't derive Data.Binary easily for NominalDiffTime.
 That's the point. You can only do so by using toReal or by adding
 data MyOwnPico = MyOwnPico only to create serialization instances.
 I don't like this kind of code duplication..

 Marc

One advantage of the current system is that is preserves data
abstraction. For example, right now NominalDiffTime is declared

 newtype NominalDiffTime = MkNominalDiffTime Pico

so it would be possible for GHC or another automated tool to derive an
instance of Read, Show, Binary, whatever for it. However, what if, in
the future, the maintainer of the Time library wanted to change this
to

 newtype NominalDiffTime = MkNominalDiffTime Double

? Now your derived instance wouldn't be the same, so your serialized
data would not be compatible even between the same version of your
library even if the version of your library stayed the same because
the time library version had same.

Even worse, what if the Time library maintainer changed it to

 newtype NominalDiffTime = MkNominalDiffTime (Int - Pico)

? Now you can't make a derived instance at all!

There's no really good reason why they would make these changes; it
seems reasonable that the Time library will stay in much the same form
for the forseeable future. However, the whole point of abstract
datatypes is that the maintainer can change the internals without
disrupting dependent packages, as long as the accessor functions has
the same semantics. In order for this to work, you can't have any
external code - even derived instances - relying on the internal
structure of abstract datatypes.

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


Re: [Haskell-cafe] Re: A typeclass for Data.Map etc?

2009-02-20 Thread Alexander Dunlap
On Fri, Feb 20, 2009 at 6:40 AM, Achim Schneider bars...@web.de wrote:
 wren ng thornton w...@freegeek.org wrote:

 (b) allows
 instances to have a fixed type for keys (like Data.Trie and
 Data.IntMap have),

 Can't we do some type magic to automagically select Data.Trie if the
 key is a (strict) bytestring?


I believe this is a key feature of Associated Types: you can create
self-optimizing libraries that select a different container
structure depending on the type.

For example,

class XMapK k where
  type XMap k :: * - *
  insert :: k - XMap k v - XMap k v

and then

instance XMapK Int where
  type XMap Int = Data.IntMap.IntMap
  insert = Data.IntMap.insert

etc.

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


Re: [Haskell-cafe] A typeclass for Data.Map etc?

2009-02-19 Thread Alexander Dunlap
On Thu, Feb 19, 2009 at 10:18 AM, Jamie Brandon jamii...@googlemail.com wrote:
 Maybe this is of interest:
 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/gmap

 The edison api is much more stable. The gmap api was already in place
 when I started working on it but I would prefer to at some point make
 it a superset of the edison api. No sense in having more than one map
 interface lying around.

 Jamie

What would really be nice is a general interface to a lot of different
types of containers that was both standardized by the community AND
used as the basis for lots of different libraries. For instance, the
new split package is a well-crafted library for dealing with splitting
lists, but it only works on lists. The exact same logic that's already
there could be used for splitting ByteStrings, Lazy ByteStrings,
Data.Sequences, some of the sequence types in Edison, fixed-length
vectors, etc., but currently, the way the package is made forces you
to use only Haskell's lazy lists. Now if we look at the zlib package,
this package decompresses data into the lazy ByteString format. So you
can't directly split data that comes out of zlib - you have to convert
it to String and then back again, which is annoying and also imposes a
performance cost. If we could figure out a way to have a general
interface to sequence-like or map-like or set-like objects, we
could make our libraries a lot more general and also more useful in
combination with each other.

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


Re: [Haskell-cafe] Re: Open unqualified imports

2009-02-04 Thread Alexander Dunlap
On Wed, Feb 4, 2009 at 4:22 PM, Henning Thielemann
lemm...@henning-thielemann.de wrote:

 On Wed, 4 Feb 2009, Simon Marlow wrote:

 Ian Lynagh wrote:

 On Fri, Jan 16, 2009 at 06:42:46AM -0800, eyal.lo...@gmail.com wrote:

 Closed-unqualified import:
 import Data.Map(Map, lookup)

 One problem with this style is that you can get lots of conflicts from
 your VCS if you have multiple people working on the same module.

 Right; in GHC we actively discourage the use of explict import lists (or
 closed-unqualified import to use the terminology of this thread).

 http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Imports

 I find that the reasons not to use explicit import lists outweigh the
 reasons to use them, at least for code that I'm working on (rather than just
 reading).

 Ideally the import lists would be maintained automatically by an IDE, and
 would be intelligently handled by the VCS.

 This will work only if you exclusively import from modules of the same
 project, where you can choose identifiers to never clash, and external
 library modules where no functions are added anymore. Certainly for GHC this
 works since the compiler as basis tool must not depend on many libraries.
 However for me the situation is that I use many libraries, each maintained
 by only a few people. Within this kind of development name clashes are more
 likely than versioning conflicts. The only style that avoids both kinds of
 conflicts is the qualified import, which I try to use whereever possible.

Another solution would be an automated tool to add explicit import
lists as part of the release process. Then you don't have to worry
about maintaining them but once you do the final release, you know
that it won't break if new functions are added to dependencies.

Perhaps I will create such a tool sometime...

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


Re: [Haskell-cafe] Quite confused by simple transformations on this code not working

2009-01-20 Thread Alexander Dunlap
Instead of declaring (/\) :: Eq a = Sentence a - Sentence a -
Sentence a, you could say (/\) :: Eq a - [a] - [a] - [a]. Then it
would work in both places. ([a] - [a] - [a] is a more general type
than [[Term a]] - [[Term a]] - [[Term a]], so functions with the
former type can be used in place of functions of the latter type but
not vice versa.)

Alex

2009/1/20 Andrew Wagner wagner.and...@gmail.com:
 So...there's just no good way to avoid the duplication?

 On Tue, Jan 20, 2009 at 11:10 PM, wren ng thornton w...@freegeek.org
 wrote:

 Andrew Wagner wrote:

 Strange little bit of code:
 http://moonpatio.com:8080/fastcgi/hpaste.fcgi/view?id=829#a829

 If I do any of the following, all of which seem natural to me, it fails
 to
 typecheck:

   1. move f out of the 'where' clause (with or without a type signature)
   2. put the same type signature on f as is on (/\)
   3. replace f with (/\) completely

 What's going on here?

 :t (nub .) . (++)
(nub .) . (++) :: (Eq a) = [a] - [a] - [a]

 :t foldr (map . (nub .) . (++))
foldr (map . (nub .) . (++)) :: (Eq a) = [[a]] - [[a]] - [[a]]

 The type you give to (/\) is more restrictive than the type of the
 expression, and f uses the generality of the expression.

 --
 Live well,
 ~wren
 ___
 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


[Haskell-cafe] Re: [Haskell-beginners] pattern matching on date type

2009-01-01 Thread Alexander Dunlap
On Thu, Jan 1, 2009 at 12:36 AM, Max.cs max.cs.2...@googlemail.com wrote:
 thanks!

 suppose we have

 data Tree a = Leaf a | Branch (Tree a) (Tree a) deriving Show

 and how I could define a function foo :: a - Tree a that

 foo a = Leaf a where a is not a type of Tree
 foo b = b where b is one of the type of Tree (Leaf or
 Branch) ?

 The following code seems not working..

 foo (Leaf a) = a
 foo a = Leaf a

 saying 'Couldn't match expected type `a' against inferred type `Btree a''

 any idea?

 Thanks,
 Max

You can't define such a function. foo :: a - Tree a, but the
definition foo b = b has the type a - a, which is why the compiler
says it can't match type a against Tree a. In general, Haskell
functions can't look at the type of their arguments: they are either
monomorphic or are polymorphic, in which case you can only use
polymorphic functions that match the polymorphic type. For the problem
you are trying to solve, you probably need to encode this logic higher
up in the overall function (e.g. have one function to deal with as
and another to deal with Tree as).

Hope that helps,
Alex
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Time for a new logo?

2008-12-17 Thread Alexander Dunlap
2008/12/17 George Pollard por...@porg.es:
 Might be interesting to try angling the ends of the stems to look
 something more like the guillemot in [1]. I might try this in Gimp but
 I'm no designer :P

 Here is what I got; I think I chose the wrong yellow :) Based it on the
 font Diavlo, which is free.


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


Re: [Haskell-cafe] Multi-parameter type class woes

2008-12-15 Thread Alexander Dunlap
2008/12/15 Mario Blazevic mblaze...@stilo.com:
 Alexander Dunlap wrote:

 On Sun, Dec 14, 2008 at 8:10 PM, Mario Blažević mblaze...@stilo.com
 wrote:

 I'll take a swing at this one:

 instance Container (Maybe x) [x] where
 wrapper = isNothing
 . . .

 That isn't a sensible definition of 'wrapper', but I believe without
 trying to compile it is completely legal.  Which wrapper do you use?

 You /don't/ have a different matching Container instance, but without
 the
 functional dependency you /might/, and ghc barfs.

   But liftWrap doesn't require any particular instance, it's a
 generic function accepting any pair of types for which there is
 an instance of Container. Instance selection (as I understand it)
 shouldn't come into play until one applies liftWrap to a
 particular type, and indeed it does cause problems there: note
 the type annotations on the last line. That part I understand
 and accept, or at least have learned to live with.

 The problem is that y is not mentioned in the signature of wrapper.
 When you call wrapper x, there could be many different instances of
 Container x y with the same x, so GHC doesn't know which version to
 call.


I guess I see it now. However, if the explicit 'Container x y ='
 context couldn't fix the y to use for instantiation of Container x y, I
 don't see any way to fix it. And if there is no way to call wrapper in any
 context, the class declaration itself is illegal and GHC should have
 reported the error much sooner. Should I create a ticket?



 You can fix this problem either by adding a functional
 dependency or by splitting wrapper out into its own class (Wrapper x,
 e.g.) so all of the type variables in the class head are mentioned in
 its type and the instance can be determined by the call.

 Thanks for asking this question, by the way. I had known about this
 issue but had never really realized why it happened. Now that I have
 thought about it, I understand it too. :)

 Hope that helps,
 Alex




I think that 
http://www.haskell.org/pipermail/haskell-cafe/2008-April/041461.html
may be relevant. It's a design decision.

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


Re: Re: [Haskell-cafe] Multi-parameter type class woes

2008-12-14 Thread Alexander Dunlap
On Sun, Dec 14, 2008 at 8:10 PM, Mario Blažević mblaze...@stilo.com wrote:
 I'll take a swing at this one:

 instance Container (Maybe x) [x] where
 wrapper = isNothing
 . . .

 That isn't a sensible definition of 'wrapper', but I believe without
 trying to compile it is completely legal.  Which wrapper do you use?

 You /don't/ have a different matching Container instance, but without the
 functional dependency you /might/, and ghc barfs.


But liftWrap doesn't require any particular instance, it's a
 generic function accepting any pair of types for which there is
 an instance of Container. Instance selection (as I understand it)
 shouldn't come into play until one applies liftWrap to a
 particular type, and indeed it does cause problems there: note
 the type annotations on the last line. That part I understand
 and accept, or at least have learned to live with.

The problem is that y is not mentioned in the signature of wrapper.
When you call wrapper x, there could be many different instances of
Container x y with the same x, so GHC doesn't know which version to
call. You can fix this problem either by adding a functional
dependency or by splitting wrapper out into its own class (Wrapper x,
e.g.) so all of the type variables in the class head are mentioned in
its type and the instance can be determined by the call.

Thanks for asking this question, by the way. I had known about this
issue but had never really realized why it happened. Now that I have
thought about it, I understand it too. :)

Hope that helps,
Alex
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Multi-parameter Type Class

2008-12-11 Thread Alexander Dunlap
2008/12/11 Thomas DuBuisson thomas.dubuis...@gmail.com:
 I see Lennart answered your question.  For more fun you could also do this
 with TypeFamilies, which are the new hot thing in Haskell type level logic.
 Since you are just getting into MPTC, FunDeps etc I figured you'd be
 interested.

 -- START CODE --
 {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies,
 TypeSynonymInstances, FlexibleInstances, TypeFamilies #-}

 data Foo = Foo Barderiving(Show)
 data Bar = Bar String deriving(Show)

 -- A family of types will evaluate from one type to another.
 -- Here, I chose the word 'Eval', which you could make more meaningful.
 -- It is basically a function over types.
 type family Eval b

 -- This is three definitions for the type function 'Eval'
 type instance Eval Foo = Integer
 type instance Eval Bar = String
 type instance Eval [x] = [Eval x]

 -- And instead of a functional dependency
 -- you have a type level function (Eval) that operates on the type 'a'.
 class ZOT a where
   zot :: a - Eval a

 instance ZOT Foo where
   zot x = 17

 instance ZOT Bar where
   zot x = Eighteen

 -- And don't forget that x must be an instance of ZOT to apply zot.
 instance (ZOT x) = ZOT [x] where
   zot xs = map zot xs

 main = do print $ zot $ Foo $ Bar Blah
   print $ zot $ Bar Blah
   print $ zot $ [Bar Blah, Bar Blah] -- No map here please
 

I don't mean to hijack the original question, but I have a question
about this code. Is this the same as saying

class ZOT a where
  type Eval a
  zot :: a - Eval a

and then appropriate instance declarations? Is there any reason to
have the type function inside or outside of the class?

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


Re: [Haskell-cafe] Data.Map.fromListWith

2008-12-06 Thread Alexander Dunlap
On Sat, Dec 6, 2008 at 12:22 PM, Paul Johnson [EMAIL PROTECTED] wrote:
 I've just been looking at the Data.Map function fromListWith.  According
 to the docs, it has the type:

 *   fromListWith* :: Ord
 http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Ord.html#t%3AOrd
 k = (a - a - a) - [(k, a)] - Map
 http://www.haskell.org/ghc/docs/latest/html/libraries/containers/Data-Map.html#t%3AMap
 k a

 I'd have thought that a better type would be

 *   fromListWith* :: Ord
 http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Ord.html#t%3AOrd
 k = (a - b - b) - [(k, a)] - Map
 http://www.haskell.org/ghc/docs/latest/html/libraries/containers/Data-Map.html#t%3AMap
 k b

 This wouldn't break any existing code, but would allow things like
 fromListWith (:) to do the Right Thing.

 Would this be a sensible change (along with the other with functions in
 the module).

 Paul.


Hi,

I don't think that type makes sense. fromListWith takes a list of
[(key,value)] and a combining function to combine the values when
there are multiple pairs with the same key. Thus, a type of (a - b -
b) for the combining function doesn't make sense because the values
are all going to have the same type (i.e. they are all as). We might
consider (a - a - b), but this doesn't make sense either because
then you have some values with type a (the ones that didn't need to
be combined) and some with type b (the ones that were combined). (a
- a - a) is really the only type that works.

I don't think fromListWith (:) makes sense either. (:) :: a - [a] -
[a], so you would end up with some values of the map as individual
items and others as lists of items. All of the values need to have the
same type.

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


Re: [Haskell-cafe] Moving the messages for compiler to another file?

2008-12-02 Thread Alexander Dunlap
On Tue, Dec 2, 2008 at 2:56 AM, nml [EMAIL PROTECTED] wrote:
 How about moving the messages for compiler to an additional file?

 My motivation is that we often face a trade-off between
 aesthetical(elegant code) and practical(efficient code).
 Like pragmas and strictness annotations, I often feel they make the
 source code ugly.
 They don't affect the semantics of our programs, do they?

 Some people would say this beautifying should be accomplished by an
 editor, like hiding/showing option for those information.

 But such separation has additional benefits.
 For instance, making the source code more compiler-independent.
 (yeah, this is not the case with language-extensions)
 And we avoid dispersing those information among our lines. (or even files)
 In some cases, it would be convenient.

 I'm not sure if this idea is reasonable, reachable or just naive.
 Suggestions?

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


One problem is that in many cases, the things that you're talking
about DO affect semantics. Consider strictness annotations:

 f (!x) = Just x
 g x = Just x
 h (Just _) = True
 h Nothing = False

Now h (f _|_) == _|_, but h (g _|_) == True, even though a strictness
annotation was the only difference between them. (For those not
already familiar with it, _|_ (bottom) is a semantically undefined
value, equivalent to an infinite loop.)

I agree that it's good to reduce semantically-irrelevant code, but I'm
not sure how feasible the proposal would be. I think GHC's rewrite
rules may be of interest in this problem (the debate between elegant
and fast code). Don Stewart has also written about this issue and has
a couple of really good posts on his blog
(http://cgi.cse.unsw.edu.au/~dons/blog/2008/05/16#fast).

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


Re: [Haskell-cafe] Could not find module ... which is hidden problem

2008-11-29 Thread Alexander Dunlap
On Sat, Nov 29, 2008 at 11:22 PM, Belka [EMAIL PROTECTED] wrote:

 Hello!

 START--
 $ sudo runghc Setup configure --user
 Configuring HCL-1.2...

 $ sudo runghc Setup build
 Preprocessing library HCL-1.2...
 Preprocessing executables for HCL-1.2...
 Building HCL-1.2...

 HCL.hs:302:7:
Could not find module `System.Random':
  it is a member of package random-1.0.0.1, which is hidden

 $ sudo ghc-pkg expose random
 Saving old package config file... done.
 Writing new package config file... done.

 $ sudo runghc Setup configure --user
 Configuring HCL-1.2...

 $ sudo runghc Setup build
 Preprocessing library HCL-1.2...
 Preprocessing executables for HCL-1.2...
 Building HCL-1.2...

 HCL.hs:302:7:
Could not find module `System.Random':
  it is a member of package random-1.0.0.1, which is hidden

 -THE-END

 Perhaps, i'm 1000th, who asks how to solve this. Sorry that didn't search
 better, but it's really tiring for a newby. :-(
 [ http://www.haskell.org/haskellwiki/Upgrading_packages/Updating_to_GHC_6.8
 Here ] found something, which maybe called a gentle explaination of what's
 going on. I have ghc ver: 6.8.2, base ver: 3.0.1.0.

 So there are 2 questions of mine:
 (1) Is there any centralized and well organized Haskell Knowledge Base,
 where it would be much easier to find solutions for popular problems?
 Anybody, please, your recommendations.
 (2) As for the topic: the only option for me would be obtaining older GHC
 (base?) - is that correct? So that require me reinstalling every Haskell
 package I have installed so far?

 Thanks in advance.
 --
 View this message in context: 
 http://www.nabble.com/%22Could-not-find-module-...-which-is-hidden%22-problem-tp20742582p20742582.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


Is the random package in the build-depends of your cabal file? If
not, that's why it's hidden. Cabal hides all of the packages that
aren't  listed in build-depends so that you can't accidentally depend
on something that you don't list.

Hope that helps.

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


Re: [Haskell-cafe] performance difference for binary-0.4.3.1 with ghc-6.8.3 and ghc-6.10

2008-10-26 Thread Alexander Dunlap
On Sun, Oct 26, 2008 at 9:36 AM, John Lato [EMAIL PROTECTED] wrote:
 Hello,

 I was experimenting with using ghc-6.10.0.20081007 on a project, and
 it seems that binary-0.4.3.1 has markedly worse performance in certain
 cases.  With the following simple test:

 import qualified Data.ByteString.Lazy as L
 import Data.Binary
 import Data.Binary.Get
 import Control.Monad

 main :: IO ()
 main = do
 b - L.readFile some_binary_file
 putStrLn $ show $ runGet getter b

 getter :: Get [Word16]
 getter = replicateM 100 getWord16le

 running this program compiled with ghc-6.10 takes about 4 times as
 long (and consumes much more memory) as when compiled with ghc-6.8.3.
 The extra time appears to be proportional to the number of elements
 processed in the Get.  Running the programs with -hT shows a clear
 memory difference, which I think is the source of the problem.  I've
 placed pdfs of that output at https://webspace.utexas.edu/latojw/data/

 The difference seems to manifest itself only when the elements are
 actually processed; changing show $ runGet  to show $ length $
 runGet  is slightly faster in 6.10.

 I was working on an Intel Mac with OS 10.4, binary-0.4.3.1, and
 bytestring-0.9.1.4.  Can anyone confirm this, or suggest what might be
 the difference?

 Thank you,
 John Lato
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


With GHC 6.8.2:

test: too few bytes. Failed reading at byte position 1613914

real0m27.573s
user0m12.917s
sys 0m0.087s

With GHC 6.11.20081003:

test: too few bytes. Failed reading at byte position 1613914

real0m21.528s
user0m14.759s
sys 0m0.135s

I'm not using the exact same versions as you are, but I seem to be
getting different results.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Linking and unsafePerformIO

2008-10-14 Thread Alexander Dunlap
On Tue, Oct 14, 2008 at 2:14 PM, Jules Bean [EMAIL PROTECTED] wrote:
 David Roundy wrote:

 On Tue, Oct 14, 2008 at 05:20:35PM +0100, Jules Bean wrote:

 Running a program on a different interpreter or compiler had better
 not change its denotation, otherwise it [the denotation] is not much
 use as a basis for reasoning.

 But you're saying above that we can't change programs, right? You
 probably won't be surprised to hear that different compilers are
 different programs.  And different packages are also different
 programs.  Are you the only one who's allowed to fix bugs?

 No. I think we must be at cross purposes.

 I'm saying that we can change programs, and that changes their denotation,
 and that's fine, and anyone can do that. But the denotation of a program is
 supposed to be something independent of a particular compiler or OS or MAC
 address or RAM size or any of the millions of other things which probably
 don't change during the single run of a program.

 Putting these things into the IO monad is not an abuse of the IO monad. It
 is simply an acknowledgement that they are runtime things, and not
 denotational constructs.


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


But they aren't runtime constructs, they are compile-time constructs,
just like how (+) has a different meaning when you are on Windows than
it does when you are on Linux: they have different ways of allocating
memory, adding two numbers, putting the result somewhere, etc. Really,
they still denote the same thing (add two numbers), they just
abstract over system-dependent details.

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


Re: [Haskell-cafe] MPFR / FFI - Nefarious (Simple?) bug

2008-10-05 Thread Alexander Dunlap
On Sun, Oct 5, 2008 at 5:38 PM, Chris Mears [EMAIL PROTECTED] wrote:
 Jared Updike [EMAIL PROTECTED] writes:

 Can someone else verify if this is a Mac/BSD only problem by compiling
 and running my code? (Does the C executableworks work? Does the
 Haskell executable noworks not work?) Can anyone on Linux and
 Windows attempt to compile/run and see if you can get the same
 results?

 I can't help you fix the problem, but can confirm that it behaves as you
 describe on my Linux system.  The program works produces correct
 output, but noworks gives:

 ==
 [...]
 290
 1.0
 291
 1.00315821571076304370386829039486164636536120569099678825575157477354990710405658927062619547595122867857873765133026050519075772712996650488675128428778696175272153632855303857710094714398932056909218681833163883482512398576534211955878126971368731378321605715030861892325510831739618679352919703855747262870175016933079782350322237289103929997053812694251557912158924211585973481445271933347978517620
 292
 [...]
 384
 1.00315821571076304370386829039486164636536120569099678825575157477354990710405658927062619547595122867857873765133026050519075772712996650488675128428778696175272153632855303857710094714398932056909218681833163883482512398576534211955878126971368731378321605715030861892325510831739618679352919703855747262870175016933079782350322237289103929997053812694251557912158924211585973481445271933347978517620
 385
 1.00315821571076304370386829039486164636536120569099678825575157477354990710405658927062619547595122867857873765133026050519075772712996650488675128428778696175272153632855303857710094714398932056909218681833163883482512398576534211955878126971368731378321605715030861892281684860507747503219323326708248193093246881500522519352192987169395899758472958160241015525770811984166890239749344848735134541218
 386
 ../get_str.c:149:  assertion failed: size_s1 = m
 Aborted
 ==

 All the values from 291-384 are the same, but 385 is slightly different.
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


My results (from Linux i686) are slightly different. I am getting

[...]
287
1.0
288
get_str.c:149:  assertion failed: size_s1 = m
Aborted

i.e. I never get the random numbers; they are all zeroes but it aborts
after 287 successful repetitions.

Changing the default heap size (with +RTS -Hsize) changes how far it
runs (running with -H32M let it go past 8000 repetitions), so this
might be a garbage-collection issue.

Hope that is some help to you.

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


Re: [Haskell-cafe] Haskell Propeganda

2008-08-28 Thread Alexander Dunlap

On Thu, 28 Aug 2008, Brandon S. Allbery KF8NH wrote:


On 2008 Aug 28, at 13:21, Tim Newsham wrote:
GNU ld supports pragmas which cause the use of certain functions to 
output warnings at link time (try compiling a C program that uses gets()). 
It occurs to me that this, either in compiler or linker, would be a nice 
thing for ghc to do when using fromJust or other partial functions.


would you include all partial functions in this, such as head?



I'd like to, but IMO head is a little more acceptable because lists aren't 
binary like Maybe.  fromJust really is the Haskell equivalent of 
dereferencing a pointer without checking if it's NULL, aside from being more 
reliably detectable.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon universityKF8NH


Tools like Neil Mitchell's Catch can do more sophisticated checking, as long as 
your program can be compiled by YHC. Sometimes fromJust can be quite useful, 
though, especially in tandem with isJust. For example,


prop_foobar :: SomeType - Property
prop_foobar x
  = isJust (someTypeToMaybe x) == fromJust x == expectedResult


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


Re: [Haskell-cafe] Type family fun

2008-08-23 Thread Alexander Dunlap
On Sat, Aug 23, 2008 at 7:55 AM, Chris Eidhof [EMAIL PROTECTED] wrote:
 Hey all,

 I was playing around with type families, and I have a strange problem.

 Suppose we have an alternative to an Either datatype:

 data (:|:) a b = Inl a | Inr b

 and a class Ix:

 class Ix i where
   type IxMap i :: * - *
   empty  :: IxMap i [Int]

 Now I want to give an instance for (a :|: b):

 instance (Ix l, Ix r) = Ix (l :|: r) where
   type IxMap (l :|: r) = BiApp (IxMap l) (IxMap r)
   empty = BiApp empty empty

 BiApp is defined as following:

 data BiApp a b c = BiApp (a c) (b c)

 However, it looks like the recursive calls to empty can't be unified, I get
 the following error message:

Couldn't match expected type `IxMap l'
   against inferred type `IxMap i'
  Expected type: IxMap (l :|: r) [Int]
  Inferred type: BiApp (IxMap i) (IxMap i1) [Int]
In the expression: BiApp empty empty
In the definition of `empty': empty = BiApp empty empty

 In the inferred type, there should be IxMap l instead of IxMap i, does
 anybody know what I'm doing wrong?

 Thanks,

 -chris

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


Hi,

I'm not very familiar with type families, but shouldn't BiApp be defined as

 data BiApp a b c = BiApp (a b) (a c)

since you're applying it as BiApp (IxMap l) (IxMap r)?

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


Re: [Haskell-cafe] Reader monad, implicit parameters, or something else altogether?

2008-08-22 Thread Alexander Dunlap
On Wed, Aug 20, 2008 at 1:49 AM, Henning Thielemann
[EMAIL PROTECTED] wrote:

 On Mon, 18 Aug 2008, [EMAIL PROTECTED] wrote:

 G'day all.

 Quoting Bjorn Buckwalter [EMAIL PROTECTED]:

 I'd store the constants in a data structure along the lines of:

 data AstroData a = AstroData
  { mu_Earth:: GravitationalParameter a
  , leapSeconds :: LeapSecondTable
  }

 I would like to know if there is any consensus on what is the best way
 to make such a data structure accessible in pure functions. Passing it
 explicitly would be a mess.

 In this situation, there isn't necessarily any shame in using a
 top-level unsafePerformIO as long as it's well-hidden:

  module AstroData (AstroData(..), globalAstroData) where

  data AstroData = AstroData Int

 But here my argument about playing around with the Planck constant becomes
 relevant.
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe


You can always change how you unsafePerformIO the data, though. If you
want to set Planck's constant to 42 (or whatever), just change the
unsafePerformIO $ whatever to unsafePerformIO $ return 42.

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


Re: [Haskell-cafe] how can this code be less?

2008-04-24 Thread Alexander Dunlap
I think you're looking for Data.List.isInfixOf.

Alex

On Thu, Apr 24, 2008 at 7:40 PM, Dan Weston [EMAIL PROTECTED] wrote:
 cetin tozkoparan wrote:

  I wrote this code and Can it be less?
  [2,4,5] list is sub list of [3,7,*2,4,5*,9] list and return True but not
 of [3,7,*4,2,5*,9] list ; return False
 
  sublist :: Eq a = [a] - [a] - Bool
  sublist [] _ = True
  sublist (_:_) []   = False
  sublist (x:xs) (y:ys)
   | x == y  =  if isEqual (x:xs) (y:ys) == False
 then sublist (x:xs) ys
 else True
   | otherwise   = sublist (x:xs) ys
 
  isEqual :: Eq a = [a] - [a] - Bool
  isEqual [] _ = True
  isEqual (_:_) [] = False
  isEqual (x:xs) (y:ys)
   | x==y= isEqual xs ys
   | otherwise= False
 

  One way is to use existing library functions as Henning suggested (but
 maybe you missed it because he mischievously changed the subject!)

  Henning Thielemann wrote:
   try 'List.tails' and 'List.isPrefixOf'

  You should be able to define sublist using only some combination of the
 following (and one pair of parentheses) in one line of code!

  import List(isPrefixOf,tails)

  (.):: (b - c) - (a - b) - a - c
  any:: (a - Bool) - [a] - Bool
  tails  :: [a] - [[a]]
  isPrefixOf :: (Eq a) = [a] - [a] - Bool
  ___
  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