Re: [Haskell-cafe] Mathematics and Statistics libraries

2012-03-26 Thread Ketil Malde
Tom Doris tomdo...@gmail.com writes:

 If you're interested in UI work, ideally we'd have something similar
 to RStudio as an environment, a simple set of windows encapsulating an
 editor, a repl, a plotting panel and help/history, this sounds
 superficial but it really has an impact when you're exploring a data
 set and trying stuff out.

I agree, this sounds really nice.

 I really disagree that we need a data frame type structure; they're an
 abomination in R, they try to accommodate event records and time
 series, and do neither well.

Just to clarify (since I think the original suggestion was mine), I
don't want to copy R's data frame (which I never quite understood,
anyway), but I'd like some standardized data structure, ideally with an
option to label columns, and functions to slice and join.  The
underlying structure can just be a list of columns (Vector) or whatever.

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants

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


Re: [Haskell-cafe] What happened with goa package repo?

2012-03-26 Thread Christopher Done
On 26 March 2012 07:24, Dmitry Malikov malikov@gmail.com wrote:
 Cloning into bare repository '/usr/portage/distfiles/egit-src/goa.git'...
 fatal: The remote end hung up unexpectedly
  * ERROR: dev-haskell/goa- failed (unpack phase):
  *   git-2_initial_clone: can't fetch from
 git://github.com/chrisdone/goa.git

 https://github.com/chrisdone/goa returns 404.

 So it seems like Chris dropped that repo. Did someone have clone of it? It
 will be nice to put it back on github.

This has been entirely unmaintained for some time. The repo is up
there now, but I haven't used it or maintained it in nearly a year.
Please clone this if you want the commits, but otherwise it is
available on hackage. I will remove it eventually.

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


Re: [Haskell-cafe] Mathematics and Statistics libraries

2012-03-26 Thread Richard O'Keefe

On 26/03/2012, at 8:35 PM, Ketil Malde wrote:
 Just to clarify (since I think the original suggestion was mine), I
 don't want to copy R's data frame (which I never quite understood,
 anyway)

A data.frame is
 - a record of vectors all the same length
 - which can be sliced and diced like a 2d matrix

It's not unlike an SQL table (think of a column-oriented data base
so a table is really a collection of named columns, but it _looks_
like a collection of rows).


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


Re: [Haskell-cafe] adding the elements of two lists

2012-03-26 Thread Jerzy Karczmarczuk

Le 26/03/2012 02:41, Chris Smith a écrit :

Of course there are rings for which it's possible to represent the
elements as lists.  Nevertheless, there is definitely not one that
defines (+) = zipWith (+), as did the one I was responding to.

What?

The additive structure does not define a ring.
The multiplication can be a Legion, all different.
Over.

Jerzy K


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


[Haskell-cafe] Execute only one step in Hood-Melville Real time queue.

2012-03-26 Thread Xinyu LIU
Hi,

I read the Hood-Melville real time queue realization in [1].
There are 2 lists maintained in queue, front and rear. When the queue gets
unbalanced due to push/pop,
it amortized the f ++ reverse r incrementally to build the new front list
based on the below mechanism

reverse r = reverse' r [] where
  reverse' [] acc = acc
  reverse' (x:xs) = reverse' xs (x:acc)

and

f ++ reverse r
== reverse (reverse f) ++ reverse r
== reverse' (reverse f) [] ++ reverse r
== reverse' (reverse' f []) (reverse' r [])

And the re-balance happens once | f | + 1 = | r |. Let's denote m = |f|.
incremental f ++ reverse r takes total 2*m + 2 steps.

In the the realization mentioned in [1], it execute 2 steps every push and
pop to make sure the
incremental computation finish before next queue re-balancing.

However, I found it's possible to execute only one step per push/pop.
because:
1. Next re-balance happens at earliest | f' | + 1 = |r|+|f|+1+1 = 2*m + 2
times by continuously push operation;
2. If we keep a copy of f, and a counter of how many elements left in f,
which need to be incrementally 'appended', by continuously m times popping
operation. we can finish the f ++ reverse r (actually, only reverse r is
needed, as all elements in f are popped)

Based on this fact, I rewrite the program as the following:

data State a = Empty
 | Reverse Int [a] [a] [a] [a] -- n, f', acc_f' r, acc_r
 | Append Int [a] [a]  -- n, rev_f', acc
 | Done [a] -- result: f ++ reverse r
   deriving (Show, Eq)

-- front, length of front, on-goint reverse state, rear, length of reverse
data RealtimeQueue a = RTQ [a] Int (State a) [a] Int
 deriving (Show, Eq)

-- we skip the empty error for pop and front
empty = RTQ [] 0 Empty [] 0

isEmpty (RTQ _ lenf _ _ _) = lenf == 0

-- O(1) time push
push (RTQ f lenf s r lenr) x = balance f lenf s (x:r) (lenr + 1)

-- O(1) time pop
pop (RTQ (_:f) lenf s r lenr) = balance f (lenf - 1) (abort s) r lenr

front (RTQ (x:_) _ _ _ _) = x

balance f lenf s r lenr
| lenr = lenf =  step f lenf s r lenr
| otherwise = step f (lenf + lenr) (Reverse 0 f [] r []) [] 0

-- execute f ++ reverse r step by step
step f lenf s r lenr =
case s' of
  Done f' - RTQ f' lenf Empty r lenr
  s' - RTQ f lenf s' r lenr
where s' = if null f then next $ next s else next s

next (Reverse n (x:f) f' (y:r) r') = Reverse (n+1) f (x:f') r (y:r')
next (Reverse n [] f' [y] r') = Append n f' (y:r')
next (Append 0 _ acc) = Done acc
next (Append n (x:f') acc) = Append (n-1) f' (x:acc)
next s = s

-- Abort unnecessary appending as the element is popped
abort (Append 0 _ (_:acc)) = Done acc -- Note! we rollback 1 elem
abort (Append n f' acc) = Append (n-1) f' acc
abort (Reverse n f f' r r') = Reverse (n-1) f f' r r'
abort s = s

Note the 'where' clause in step function. This is because we need an extra
step to change the state from (Append 0 _ xs) to (Done xs).

I tested this program with invariant testing with QuickCheck. The behavior
is correct as other queue implementation.

The program can be found here:

https://github.com/liuxinyu95/AlgoXY/blob/algoxy/datastruct/elementary/queue/src/RealtimeQueue.hs

Reference:
[1]. Chris Okasaki. ``Purely functional data structures''. P102. Section
8.2.1. Cambridge University Press. ISBN 0521663504
-- 
Larry, LIU Xinyu
https://sites.google.com/site/algoxy/
https://github.com/liuxinyu95/AlgoXY
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Using HaXml

2012-03-26 Thread Yves Parès
Thanks!
Apparently some also have problems to find tutorials/help with HaXml [1].

 I'm curious to hear how HaXml compares to HXT / HXML / TagSoup.
I'm curious too. I've read that HXML is old and not longer maintained.
I believe besides the rewriting of the API to use arrows, HaXml adds
checking capabilities like use of RelaxNG.

[1]
http://stackoverflow.com/questions/6082350/how-to-access-some-xml-data-with-haskell-using-haxml

Le 25 mars 2012 11:06, aditya bhargava bluemangrou...@gmail.com a écrit :

 I don't know much about HaXml, but HXT is based on it and comes with a
 tutorial:

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

 I also show some basic functionality of HXT in this blog post:


 http://adit.io/posts/2012-03-10-building_a_concurrent_web_scraper_with_haskell.html

 I'm curious to hear how HaXml compares to HXT / HXML / TagSoup.


 Adit



 On Sun, Mar 25, 2012 at 1:34 AM, Yves Parès yves.pa...@gmail.com wrote:

 Hello café,

 Provided what I read, HaXml seems to be the recommended library for
 parsing XML files (I'm trying to browse and alter spreadsheets (ODS) and
 possibly release a package when I'm done), is there somewhere tutorials on
 how to use it?
 I used 'xml' package by the past, but HaXml is more substantial.

 Thanks.

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




 --
 adit.io

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


[Haskell-cafe] difficulty building (some) TH packages with ghc-7.4.1

2012-03-26 Thread John Lato
Hello,

I've run into an odd problem when building certain packages that use
Template Haskell with GHC-7.4.1.  For example, RepLib:

$ cabal --version
cabal-install version 0.13.3
using version 1.14.0 of the Cabal library

$ cabal install -O2 -w ~/.ghc-7.4.1/bin/ghc RepLib --reinstall
Resolving dependencies...
Configuring RepLib-0.5.2...
Building RepLib-0.5.2...
Preprocessing library RepLib-0.5.2...
[ 1 of 12] Compiling Generics.RepLib.R ( Generics/RepLib/R.hs,
dist/build/Generics/RepLib/R.o )
[ 2 of 12] Compiling Generics.RepLib.R1 ( Generics/RepLib/R1.hs,
dist/build/Generics/RepLib/R1.o )
[ 3 of 12] Compiling Generics.RepLib.Derive (
Generics/RepLib/Derive.hs, dist/build/Generics/RepLib/Derive.o )
[ 4 of 12] Compiling Generics.RepLib.PreludeReps (
Generics/RepLib/PreludeReps.hs,
dist/build/Generics/RepLib/PreludeReps.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package type-equality-0.1.0.2 ... linking ... done.
Loading package array-0.4.0.0 ... linking ... done.
Loading package deepseq-1.3.0.0 ... linking ... done.
Loading package containers-0.4.2.1 ... linking ... done.
Loading package pretty-1.1.1.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
Loading package transformers-0.2.2.0 ... linking ... done.
Loading package mtl-2.0.1.0 ... linking ... done.
cabal: Error: some packages failed to install:
RepLib-0.5.2 failed during the building phase. The exception was:
ExitFailure 11

This is without library profiling enabled.  If I enable library
profiling, the unprofiled build is fine but the profiled build exits
with the same error, at the same location.

If I pass the -v argument to cabal-install, the package builds fine
with profiling disabled.  The -v flag makes no difference with
profiling enabled, although some packages (but not RepLib) work with
-v2

I haven't seen this with ghc-7.2.*, but I'm guessing this is some sort
of cabal-install bug.  Has anyone else witnessed anything like this?

Thanks,
John L.

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


[Haskell-cafe] ANN: Latest package versions on Hackage as JSON/JSONP

2012-03-26 Thread Simon Hengel
Hi,
I provide a relation between /package name/ and /latest version/ on
Hackage as both JSON and JSONP.

http://www.typeful.net/~tbot/hackage/

This are static files, and they are regenerated whenever new packages
are uploaded (with a delay of about one minute).

Two simple usage examples are given in the README[1].
 
Feel free to access this information for whatever purpose!

Cheers,
Simon

[1] https://github.com/sol/hackage-jsonp#readme

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


Re: [Haskell-cafe] adding the elements of two lists

2012-03-26 Thread Jake McArthur
This is interesting because it seems to be a counterexample to the claim
that you can lift any Num through an Applicative (ZipList, in this case).
It seems like maybe that only works in general for monoids instead of rings?
On Mar 25, 2012 8:43 PM, Chris Smith cdsm...@gmail.com wrote:

 Jerzy Karczmarczuk jerzy.karczmarc...@unicaen.fr wrote:
  Le 26/03/2012 01:51, Chris Smith a écrit :
 
  instance (Num a) = Num [a] where
  xs + ys = zipWith (+) xs ys
 
  You can do this in the sense that it's legal Haskell... but it is a bad
 idea [...]

  It MIGHT be a ring or not. The real problem is that one should not
 confuse
  structural and algebraic (in the classical sense) properties of your
  objects.

 Of course there are rings for which it's possible to represent the
 elements as lists.  Nevertheless, there is definitely not one that
 defines (+) = zipWith (+), as did the one I was responding to.  By the
 time you get a ring structure back by some *other* set of rules,
 particularly for multiplication, the result will so clearly not be
 anything like a general Num instance for lists that it's silly to even
 be having this discussion.

 --
 Chris Smith

 ___
 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] adding the elements of two lists

2012-03-26 Thread Chris Smith
Jerzy Karczmarczuk jerzy.karczmarc...@unicaen.fr wrote:
 Le 26/03/2012 02:41, Chris Smith a écrit :
 Of course there are rings for which it's possible to represent the
 elements as lists.  Nevertheless, there is definitely not one that
 defines (+) = zipWith (+), as did the one I was responding to.

 What?

 The additive structure does not define a ring.
 The multiplication can be a Legion, all different.

I'm not sure I understand what you're saying there.  If you were
asking about why there is no ring on [a] that defines (+) = zipWith
(+), then here's why.  By that definition, you have [1,2,3] + [4,5] =
[5,7].  But also [1,2,42] + [4,5] = [5,7].  Addition by [4,5] is not
one-to-one, so [4,5] cannot be invertible.

-- 
Chris Smith

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


Re: [Haskell-cafe] good lightweight web-framework like sinatra?

2012-03-26 Thread dag.odenh...@gmail.com
On 21 March 2012 03:45, serialhex serial...@gmail.com wrote:

 i'm looking for something lightweight, that dosnt need it's own
 server, can easily run on cgi on an apache with minimal work, and
 dosn't have many dependancies. i was looking at yesod, but it is
 bigger than i need for my site (at this point) and would take too much
 work to get running on my webhost.  though i am looking forward to
 learning it and using it in the future, i just need something that
 will play nicely with apache  cgi...


You could use WAI without warp/yesod? There's a CGI handler in wai-extra.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] adding the elements of two lists

2012-03-26 Thread Jerzy Karczmarczuk

Le 26/03/2012 16:31, Chris Smith a écrit :

If you were
asking about why there is no ring on [a] that defines (+) = zipWith
(+), then here's why.  By that definition, you have [1,2,3] + [4,5] =
[5,7].  But also [1,2,42] + [4,5] = [5,7].  Addition by [4,5] is not
one-to-one, so [4,5] cannot be invertible.
So, * the addition* is not invertible, why did you introduce rings to 
this discussion, if the additive group within is already lousy?...
OK I see now. You are only interested in the explicitly ambiguous usage 
of the element-wise addition which terminates at the shortest term...
But I don't care about using (+) = zipWith (+) anywhere, outside of a 
programming model / framework, where you keep the sanity of your data. 
In my programs I KNEW that the length of the list is either fixed, or of 
some minimal size (or infinite). Your [4,5] simply does not belong to MY 
rings, if I decided to keep the other one.


Jerzy K.


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


Re: [Haskell-cafe] adding the elements of two lists

2012-03-26 Thread Chris Smith
On Mon, Mar 26, 2012 at 10:18 AM, Jerzy Karczmarczuk
jerzy.karczmarc...@unicaen.fr wrote:
 So, * the addition* is not invertible, why did you introduce rings ...

My intent was to point out that the Num instance that someone
suggested for Num a = Num [a] was a bad idea.  I talked about rings
because they are the uncontroversial part of the laws associated with
Num: I think everyone would agree that the minimum you should expect
of an instance of Num is that its elements form a ring.

In any case, the original question has been thoroughly answered... the
right answer is that zipWith is far simpler than the code in the
question, and that defining a Num instance is possible, but a bad idea
because there's not a canonical way to define a ring on lists.  The
rest of this seems to have devolved into quite a lot of bickering and
one-ups-manship, so I'll back out now.

-- 
Chris Smith

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


Re: [Haskell-cafe] adding the elements of two lists

2012-03-26 Thread wren ng thornton

On 3/26/12 8:16 AM, Jake McArthur wrote:

This is interesting because it seems to be a counterexample to the claim
that you can lift any Num through an Applicative (ZipList, in this case).
It seems like maybe that only works in general for monoids instead of rings?


I'm not so sure about that. The Applicative structure of ZipLists is 
specifically defined for infinite lists (cf., pure = repeat). And in the 
case of infinite lists the (+) = zipWith(+) definition works just fine, 
since we don't have to worry about truncation. I wasn't aware that Num 
was supposed to be liftable over any Applicative, but this doesn't seem 
like a counterexample...


--
Live well,
~wren

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


[Haskell-cafe] Is there a generic way to detect mzero?

2012-03-26 Thread Ting Lei

Hi,

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

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

And I got the expected result:

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

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

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


I got a warning:

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

And the result is also not as intended (see also can0):

*Main can (\x - Just x) 1
False


Can anyone help to explain why this wouldn't work or if there is a workaround 
to use Monadplus and mzero (or Monad and fail) to achieve this?


Thanks in advance for your help

Ting

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


Re: [Haskell-cafe] Is there a generic way to detect mzero?

2012-03-26 Thread Jeff Shaw



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


I got a warning:

__testError.hs:31:11:
Warning: Pattern match(es) are overlapped
 In a case alternative: _ - ...
Ok, modules loaded: Main.
The problem here is that when you match on f x, your first match is an 
identifier that matches anything at all, and binds it to mzero. I think 
what you're looking for is


can f x = case f x of
x' | x' == mzero - False
_ - True

Jeff

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


Re: [Haskell-cafe] Is there a generic way to detect mzero?

2012-03-26 Thread Tobias Brandt
On 26 March 2012 20:33, Ting Lei tin...@hotmail.com wrote:

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

In the first pattern `mzero' is just a variable and matches
anything, as does `_'. So, naturally, both patterns overlap.

I don't see any way to write this without requiring `Eq m'.

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


Re: [Haskell-cafe] Is there a generic way to detect mzero?

2012-03-26 Thread dag.odenh...@gmail.com
On 26 March 2012 21:11, Jeff Shaw shawj...@msu.edu wrote:


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


 I got a warning:

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

 The problem here is that when you match on f x, your first match is an
 identifier that matches anything at all, and binds it to mzero. I think
 what you're looking for is


 can f x = case f x of
x' | x' == mzero - False
_ - True


can f x = f x /= mzero
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Is there a generic way to detect mzero?

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

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

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

 And I got the expected result:

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

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

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


 I got a warning:

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


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

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

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

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

Antoine

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


Re: [Haskell-cafe] Is there a generic way to detect mzero?

2012-03-26 Thread Harry Terkelsen
Jeff,

I don't think your code works in general, since it is not guaranteed that
x' == mzero is allowed unless (m b) is an instance of Eq. I'm unsure if you
are able to test for mzero in general.

Harry

On Mon, Mar 26, 2012 at 3:11 PM, Jeff Shaw shawj...@msu.edu wrote:


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


 I got a warning:

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

 The problem here is that when you match on f x, your first match is an
 identifier that matches anything at all, and binds it to mzero. I think
 what you're looking for is


 can f x = case f x of
x' | x' == mzero - False
_ - True

 Jeff

 __**_
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe

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


Re: [Haskell-cafe] Is there a generic way to detect mzero?

2012-03-26 Thread Roman Cheplyaka
* Ting Lei tin...@hotmail.com [2012-03-26 11:33:16-0700]
 I was writing a code trying to use MonadPlus to detect some error
 cases (representing missing values etc. in pure code).

You are probably looking for the MonadError class.

There's also the MonadLogic class (which allows to literally detect
mzero), but if you simply need to catch errors, it is not as
appropriate as MonadError.

-- 
Roman I. Cheplyaka :: http://ro-che.info/

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


Re: [Haskell-cafe] Is there a generic way to detect mzero?

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

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

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

 And I got the expected result:

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

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

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


 I got a warning:

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


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

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

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

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

Well, if you accept the following MonadPlus laws:

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

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

Erik

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


Re: [Haskell-cafe] ANN: Latest package versions on Hackage as JSON/JSONP

2012-03-26 Thread aditya bhargava
Looks cool! One suggestion: make it a webservice I can use like:

typeful.net/~tbot/hackage/[package name]

example:
typeful.net/~tbot/hackage/aeson

So that I don't have to download an 83k file for every request.

Adit


On Mon, Mar 26, 2012 at 4:12 AM, Simon Hengel s...@typeful.net wrote:

 Hi,
 I provide a relation between /package name/ and /latest version/ on
 Hackage as both JSON and JSONP.

http://www.typeful.net/~tbot/hackage/

 This are static files, and they are regenerated whenever new packages
 are uploaded (with a delay of about one minute).

 Two simple usage examples are given in the README[1].

 Feel free to access this information for whatever purpose!

 Cheers,
 Simon

 [1] https://github.com/sol/hackage-jsonp#readme

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




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


Re: [Haskell-cafe] Is there a generic way to detect mzero?

2012-03-26 Thread Ting Lei

Hi Antoine and Tobias (and everyone else),

Thanks a lot for your answers. They are really helpful

Can you please show me how to use the (Eq m) constraint to do this?

Also, my general question (probably novice-level) is that in monadic 
programming, you can convert not necessarily monadic codes into monadic ones.
I know for many cases, it is impossible to do the reverse conversion, e.g. you 
can't make a function involving real IO operations into a pure code.
In other cases, for example, I may need to using things like Nothing as the 
null value as in other programming languages, just to represent a special 
missing value outside the regular type.
Is mzero a reasonable replacement for this or is there any reasonable 
(abstract) approximation in Haskell for doing this? (Like null, I need the 
ability to detect it.)

Thanks,

Ting


 From: aslat...@gmail.com
 Date: Mon, 26 Mar 2012 14:24:09 -0500
 Subject: Re: [Haskell-cafe] Is there a generic way to detect mzero?
 To: tin...@hotmail.com
 CC: haskell-cafe@haskell.org
 
 On Mon, Mar 26, 2012 at 1:33 PM, Ting Lei tin...@hotmail.com wrote:
  Hi,
 
  I was writing a code trying to use MonadPlus to detect some error cases
  (representing missing values etc. in pure code). With the Maybe monad, I can
  do this:
 
  can0 :: (a - Maybe b) - a - Bool
  can0 f x = case f x of
Nothing - False
Just  x - True
 
  And I got the expected result:
 
  *Main can0 (\x - Just x) 1
  True
 
  But, when I try to generalize this using MonadPlus, as follows:
 
  can :: (MonadPlus m) = (a - m b) - a - Bool
  can f x = case f x of
  mzero - False
  _ - True
 
 
  I got a warning:
 
  __testError.hs:31:11:
  Warning: Pattern match(es) are overlapped
   In a case alternative: _ - ...
  Ok, modules loaded: Main.
 
 
 Well, you can sort of do it with only MonadPlus - but it really
 depends on your choice of Monad whether or not it does anything like
 what you want:
 
 can :: (MonadPlus m) = (a - m ()) - a - m Bool
 can f x = (f x  return True) | return false
 
 For 'Maybe' this works great, but for something like 'List' I couldn't
 even tell you what it would do without reasoning through it.
 
 So you might be better off with the suggestion from Tobias using Eq
 
 Antoine
  ___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] adding the elements of two lists

2012-03-26 Thread Richard O'Keefe

On 27/03/2012, at 5:18 AM, Jerzy Karczmarczuk wrote:

 But I don't care about using (+) = zipWith (+) anywhere, outside of a 
 programming model / framework, where you keep the sanity of your data. In my 
 programs I KNEW that the length of the list is either fixed, or of some 
 minimal size (or infinite). Your [4,5] simply does not belong to MY rings, if 
 I decided to keep the other one.

And *that* is why I stopped trying to define instance Num t = Num [t].
If I KNEW that the length of the lists is ... fixed ... then the type
wasn't *really* [t], but some abstract type that happened to be implemented
as [t], and that abstract type deserved a newtype name of its own.

Naming the type
 - makes the author's intent clearer to readers
 - lets the compiler check it's used consistently
 - lets you have instances that don't match instances for
   other abstract types that happen to have the same implementation
 - provides a natural place to document the purpose of the type
 - gives you a way to enforce the intended restrictions
all for zero run-time overhead.



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


Re: [Haskell-cafe] Is there a generic way to detect mzero?

2012-03-26 Thread Antoine Latter
On Mon, Mar 26, 2012 at 4:25 PM, Ting Lei tin...@hotmail.com wrote:
 Hi Antoine and Tobias (and everyone else),

 Thanks a lot for your answers. They are really helpful

 Can you please show me how to use the (Eq m) constraint to do this?

 Also, my general question (probably novice-level) is that in monadic
 programming, you can convert not necessarily monadic codes into monadic
 ones.
 I know for many cases, it is impossible to do the reverse conversion, e.g.
 you can't make a function involving real IO operations into a pure code.
 In other cases, for example, I may need to using things like Nothing as the
 null value as in other programming languages, just to represent a special
 missing value outside the regular type.
 Is mzero a reasonable replacement for this or is there any reasonable
 (abstract) approximation in Haskell for doing this? (Like null, I need the
 ability to detect it.)

I think using 'Maybe' (with Nothing) is perfect for this - this
function should come in handy:

http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Maybe.html#v:isNothing

Antoine

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


Re: [Haskell-cafe] adding the elements of two lists

2012-03-26 Thread Jake McArthur
Well, ZipList's pure is indeed repeat, but there is nothing about ZipList
restricting it to infinite lists. As long as pure is repeat, I'm pretty
sure any other value can still be finite without violating Applicative's
laws.
On Mar 26, 2012 1:02 PM, wren ng thornton w...@freegeek.org wrote:

 On 3/26/12 8:16 AM, Jake McArthur wrote:

 This is interesting because it seems to be a counterexample to the claim
 that you can lift any Num through an Applicative (ZipList, in this case).
 It seems like maybe that only works in general for monoids instead of
 rings?


 I'm not so sure about that. The Applicative structure of ZipLists is
 specifically defined for infinite lists (cf., pure = repeat). And in the
 case of infinite lists the (+) = zipWith(+) definition works just fine,
 since we don't have to worry about truncation. I wasn't aware that Num was
 supposed to be liftable over any Applicative, but this doesn't seem like a
 counterexample...

 --
 Live well,
 ~wren

 __**_
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://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] Need a backup GSOC to apply for? Last minute new proposal -- memory reuse analysis for GHC

2012-03-26 Thread Ryan Newton
Hi potential GSOC'ers,

If there are multiple students interested in the project you're applying to
it's a good idea to put in more than one application.

This is a project proposal that would focus on performance analysis -- in
particular in reusing some of the tools for analyzing memory access
patterns in the context of Haskell:

   http://hackage.haskell.org/trac/summer-of-code/ticket/1619

I think this project would yield pretty good bang for the buck because
almost all the pieces are already there.  They just need to be combined,
polished, documented, and evangelized.

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


Re: [Haskell-cafe] Is there a generic way to detect mzero?

2012-03-26 Thread Chris Wong
On Tue, Mar 27, 2012 at 11:03 AM, Antoine Latter aslat...@gmail.com wrote:
 On Mon, Mar 26, 2012 at 4:25 PM, Ting Lei tin...@hotmail.com wrote:
 Hi Antoine and Tobias (and everyone else),

 Thanks a lot for your answers. They are really helpful

 Can you please show me how to use the (Eq m) constraint to do this?

 Also, my general question (probably novice-level) is that in monadic
 programming, you can convert not necessarily monadic codes into monadic
 ones.
 I know for many cases, it is impossible to do the reverse conversion, e.g.
 you can't make a function involving real IO operations into a pure code.
 In other cases, for example, I may need to using things like Nothing as the
 null value as in other programming languages, just to represent a special
 missing value outside the regular type.
 Is mzero a reasonable replacement for this or is there any reasonable
 (abstract) approximation in Haskell for doing this? (Like null, I need the
 ability to detect it.)

 I think using 'Maybe' (with Nothing) is perfect for this - this
 function should come in handy:

 http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-Maybe.html#v:isNothing

Ting,

It's often not good style to check Nothing explicitly, rather, it's
better to use monads to thread it through automatically.

If you have many functions that return a Maybe, then you can chain
them together using do syntax:

frobnicate = do
foo - function1
bar - function2 foo
return (bar + 1)

If any of the functions in the chain return Nothing, then the monad
will short circuit and the whole expression will result in Nothing.
The - acts like an automatic null check.

Chris

 Antoine

 ___
 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] good lightweight web-framework like sinatra?

2012-03-26 Thread aditya bhargava
Here's another Miku / Sinatra-like framework that looks interesting:

https://github.com/xich/scotty

From the README:


My issue with miku is that it uses the Hack2 interface
instead of WAI (they are analogous, but the latter seems to have more traction),
and that it is written using a custom prelude called Air



Adit


On Mon, Mar 26, 2012 at 8:09 AM, dag.odenh...@gmail.com 
dag.odenh...@gmail.com wrote:

 On 21 March 2012 03:45, serialhex serial...@gmail.com wrote:

 i'm looking for something lightweight, that dosnt need it's own
 server, can easily run on cgi on an apache with minimal work, and
 dosn't have many dependancies. i was looking at yesod, but it is
 bigger than i need for my site (at this point) and would take too much
 work to get running on my webhost.  though i am looking forward to
 learning it and using it in the future, i just need something that
 will play nicely with apache  cgi...


 You could use WAI without warp/yesod? There's a CGI handler in wai-extra.

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




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