[Haskell-cafe] TFM09: Last CFP (FMWeek, Eindhoven, November 6th 2009)

2009-05-18 Thread J.N. Oliveira


   TFM2009
 2nd Int. FME Conference on Teaching Formal Methods
"Widening Access to Formal Methods"

   Friday, November 6th 2009, co-located with
 FM2009 : 16th International Symposium on Formal Methods
Eindhoven, the Netherlands, November 2 - November 6, 2009

   CALL FOR PAPERS

(URL: http://www.di.uminho.pt/tfm09)


1. About the conference
---
Ten years after the First World Formal Methods Congress (FM'99) in  
Toulouse,
formal methods communities from all over the world will once again  
have an
opportunity to come together.  As part of the First Formal Methods  
Week event
surrounding the FM2009 conference in Eindhoven, Formal Methods Europe  
will
be organizing TFM2009, the Second International Conference on  
Teaching Formal

Methods.

The conference will serve as a forum to explore the successes and  
failures

of Formal Methods (FM) education, and to promote cooperative projects to
further education and training in FMs. We would like to provide a  
forum for
lecturers, teachers, and industrial partners to discuss their  
experience,

present their pedagogical methodologies, and explore best practices.

TFM2009 follows in a series of recent events on teaching formal methods,
including: two BCS-FACS TFM workshops (Oxford in 2003, and London in  
2006),

the TFM 2004 conference in Ghent (with proceedings published as Springer
LNCS Volume 3294), the FM-Ed 2006 workshop (Hamilton, co-located with  
FM'06),

FORMED (Budapest, at ETAPS 2008), FMET 2008 (Kitakyushu 2008, co-located
with ICFEM), etc.

2. Topics of interest
-
Formal methods (FM) have an important role to play in the development of
complex computing systems - a role acknowledged in industrial  
standards such
as IEC 61508 and ISO/IEC 15408, and in the increasing use of precise  
modeling

notations, semantic markup languages, and model-driven techniques. There
is a growing need for software engineers who can work effectively  
with simple,
mathematical abstractions, and with practical notions of inference  
and proof.
However, there is little clear guidance ? for educators, for  
managers, or
for the engineers themselves ? as to what might comprise a basic  
education
in FM. Neither the present IEEE/ACM Software Engineering Body of  
Knowledge
(SWEBOK) nor the forthcoming Graduate Software Engineering Reference  
Curriculum
(GSWERC) provide the kind of specific information that teachers and  
practitioners

need to establish an adequate, balanced programme of learning in FM.

Original contributions are solicited that provide insight, opinions, and
suggestions for courses of action regarding the teaching FMs,  
including but

not limited to the following aspects:

* experiences of teaching FMs, both successful and unsuccessful;
* educational resources including the use of books, case studies  
and the internet;

* the education of weak and mathphobic students;
* the integration, or otherwise, of FMs into the curriculum,  
including
  contributions to the definition of a Formal Methods Body of  
Knowledge (FMBOK);

* the advantages of FM-trained graduates in the workplace;
* changing attitudes towards FMs in students, academic staff and  
practitioners;

* the necessary mathematical background.

The conference proceedings will be published by Springer-Verlag in  
the LNCS series.

Submissions may be up to 20 pages long using Springer's LNCS format.

3. Important dates
--
Please put the following dates in your diary:

Submission deadline May 25, 2009
Notification of acceptance  July 6, 2009
Final version   August 3, 2009

4. How to submit

Papers for TFM2009 will be processed through the EasyChair conference  
management

system. To submit your paper, please visit:

  http://www.easychair.org/conferences/?conf=tfm2009

5. Invited speakers
---
To be announced

6. Programme Committee
--
Izzat Alsmadi   (North Dakota State University, USA)
Dines Bjorner   (IIMM Institute, Denmark)
Eerke Boiten(University of Kent, UK)
Raymond Boute   (Universiteit Gent, Belgium)
Andrew Butterfield  (Trinity College, Dublin)
Jim Davies  (University of Oxford, UK)
David Duce  (Oxford Brookes University, UK)
John Fitzgerald (University of Newcastle upon Tyne, UK)
Jeremy Gibbons  (University of Oxford, UK)
Randolph Johnson(National Security Agency, USA)
Michael Mac an Airchinnigh  (Trinity College, Dublin)
Dino Mandrioli  (Politecnico di Milano, Italy)
Jose Oliveira   (Universidade do Minho, Portugal)
Kees Pronk  (Technische Universiteit Delft, NL)
Bernhard Schaetz(Tecnical University of Munique, Germany)
Wolfgang Schreiner  (Johannes Kepler University Linz, Austria)
Simao Melo de Sousa (Universidade d

[Haskell-cafe] community.haskell.org and code.haskell.org problems

2009-05-18 Thread Neil Mitchell
Hi,

I regularly (almost daily) have problems reaching both community and
code.haskell.org, getting 500 server error messages. I've decided to
make all my Haskell code available on community, which means that when
it goes down, I can't access my repos - which is not great.

Is there a reason for the poor reliability of these servers? Can
anything be done to improve them? I'm very grateful for the
availability of the service, but I know of servers running on Windows
laptops which have far higher uptime :-)

Thanks

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


Re: [Haskell-cafe] Free theorems for dependent types?

2009-05-18 Thread Conor McBride

Hi

Questions of parametricity in dependent types are made more
complex by the way in which the "Pi-type"

  (x : S) -> T

corresponds to universal quantification. It's good to think
of this type as a very large product, tupling up individual
T's for each possible x you can distinguish by observation.
"For all x" here means "For each individual x".

By contrast, your typical universally quantified type

  forall x. t

gives you fantastic guarantees of ignorance about x! It's
really a kind of intersection. "For all x" here means
"For a minimally understood x" --- your program should work
even when x is replaced by a cardboard cutout rather than
an actual whatever-it-is, and this guarantees the
uniformity of operation which free theorems exploit.
I'm reminded of the Douglas Adams line "We demand rigidly
defined areas of doubt and uncertainty.".

In the dependent case, how much uniformity you get depends
on what observations are permitted on the domain. So what's
needed, to get more theorems out, is a richer language of
controlled ignorance. There are useful developments:

  (1) Barras and Bernardo have been working on a dependent
type system which has both of the above foralls, but
distinguishes them. As you would hope, the uniform
forall, its lambda, and application get erased between
typechecking and execution. We should be hopeful for
parametricity results as a consequence.

  (2) Altenkirch, Morris, Oury, and I have found a way
(two, in fact, and there's the rub) to deliver
quotient structures, which should allow us to specify
more precisely which observations are available on a
given set. Hopefully, this will facilitate parametric
reasoning --- if you can only test this, you're bound
to respect that, etc. My favourite example is the
recursion principle on *unordered* pairs of numbers
(N*N/2).

uRec :
(P : N*N/2 -> Set) ->
((y : N) -> P (Zero, y)) ->
((xy : N*N/2) -> P xy -> P (map Suc xy)) ->
(xy : N*N/2) -> P xy

Given an unordered pair of natural numbers, either
one is Zero or both are Suc, right? You can define
some of our favourite operators this way.

add  = uRec (\ _ -> N) (\ y -> y) (\ _ -> Suc . Suc)
max  = uRec (\ _ -> N) (\ y -> y) (\ _ -> Suc)
min  = uRec (\ _ -> N) (\ y -> y) (\ _ -> id)
(==) = uRec (\ _ -> Bool) isZero (\ _ -> id)

I leave multiplication as an exercise.

The fact that these operators are commutative is
baked into their type.

To sum up, the fact that dependent types are good at
reflection makes them bad at parametricity, but there's
plenty of work in progress aimed at the kind of information
hiding which parametricity can then exploit.

There are good reasons to be optimistic here.

All the best

Conor

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


Re: [Haskell-cafe] tips on using monads

2009-05-18 Thread Neil Brown

Michael P Mossey wrote:
I've got one of those algorithms which "threatens to march off the 
right edge" (in the words of Goerzen et al). I need something like a 
State or Maybe monad, but this is inside the IO monad. So I presume I 
need StateT or MaybeT. However, I'm still (slowly) learning about 
monads from first principles. I thought I might present my code and 
get some pointers... maybe someone could actually show me how to 
rewrite it, which would be a neat way to see MaybeT and StateT in 
action. I'm hoping to get anything from a one-line response to a 
rewrite of my code. Anything will help.


Here's a version using ErrorT from mtl.  I added some missing IO bits on 
your types; the type error that remains is for you to fix :-)  With 
ErrorT you can use throwError when you want to break out of the block 
and give back an error, which seems to fit what you were doing.  The 
downside is you have to add all these liftIO bits wherever you do a 
plain IO computation.


insertNote :: NoteRecord -> Connection -> IO ()
insertNote nr conn = either putStrLn return =<< runErrorT
  (do -- Check if it exists in the database already.
  status <- liftIO $ checkPreExistingText nr conn
  when status $ throwError "Skipping... text exists already."
  -- Find best fit for all topics and source.
  -- See type signatures below.
  bestFitTopics <- liftIO $ fitTopics nr conn
  bestFitSource <- liftIO $ fitSource nr conn
  case any isNothing bestFitTopics of
True -> throwError "Error... some topic couldn't be matched."
False ->
  case bestFitSource of
Nothing -> throwError "Error.. source couldn't be matched."
_ -> do b <- liftIO $ isUserOkay nr bestFitTopics bestFitSource
when (not b) $ throwError "Abort due to user request."
-- Create a new NoteRecord with matched
-- and validated topics/source.
let nrValidated =
  nr { recordTopics = bestFitTopics
 , recordSource = bestFitSource }
liftIO $ insertRow nrValidated conn
  )

checkPreExistingText :: NoteRecord -> Connection -> IO Bool
fitTopics :: NoteRecord -> Connection -> IO [Maybe String]
fitSource :: NoteRecord -> Connection -> IO (Maybe String)
isUserOkay :: NoteRecord -> [Maybe String] -> Maybe String -> IO Bool
insertRow :: NoteRecord -> Connection -> IO ()


Thanks,

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


[Haskell-cafe] community.haskell.org and code.haskell.org problems

2009-05-18 Thread Neil Mitchell
Hi,

I regularly (almost daily) have problems reaching both community and
code.haskell.org, getting 500 server error messages. I've decided to
make all my Haskell code available on community, which means that when
it goes down, I can't access my repos - which is not great.

Is there a reason for the poor reliability of these servers? Can
anything be done to improve them? I know of servers running on Windows
laptops which have far higher uptime :-)

Thanks

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


Re: [Haskell-cafe] ghc ./configure stalls on docbook DTD

2009-05-18 Thread Simon Marlow

On 13/05/2009 19:53, Donnie Jones wrote:

Hello Dan,

Best place to ask is glasgow-haskell-us...@haskell.org since that is
the GHC users list.
I have CC'd your email to the GHC user list.

Cheers.
--
Donnie Jones

On Wed, May 13, 2009 at 1:35 PM, Dan  wrote:

Hi,

Not sure if this is the right place to ask.
GHC 6.10.3 source dist: ./configure takes about 10 minutes to look for
DocBook DTD and another 10 to look for DocBook XSL directory.  I was writing
this e-mail thinking it had completely crashed.  Any reason why it's so
ridiculously slow? A look at 'top' says the CPU is mostly idle during this
time, but xmllint is running.


I have the following complaint from Roman in my inbox, which I think is 
about the same thing:


> one big nuisance when building ghc is that configure tries to connect 
> to the internet. The culprit is the FP_GEN_DOCBOOK_XML macro in

> aclocal.m4 which is used when checking for DocBook DTD. It generates
> an XML file which references http://www.oasis-open.org/docbook/xml/4.2
> /docbookx.dtd and then runs xmllint which, naturally, wants to load
> the dtd. Depending on the quality of my internet connection and on
> the availability of oasis-open.org this check sometimes (infrequently
> but very annoyingly) takes up to a 2 or 3 minutes for me. Given that
> the DTD in question can be freely copied, why not redistribute it
> with ghc?

> Another www reference is in FP_GEN_FO (to
> http://www.w3.org/1999/XSL/Format) but that never seems to bite me.

I know almost but not quite exactly nothing about how to find DTDs.  But 
I do recall that Duncan mentioned to me recently that there's a much 
better way to do this - Duncan?


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


Re: [Haskell-cafe] tips on using monads

2009-05-18 Thread Claus Reinke
I've got one of those algorithms which "threatens to march off the right edge" (in the words of 
Goerzen et al). I need something like a State or Maybe monad, but this is inside the IO monad. So 
I presume I need StateT or MaybeT. However, I'm still (slowly) learning about monads from first 
principles. I thought I might present my code and get some pointers... maybe someone could 
actually show me how to rewrite it, which would be a neat way to see MaybeT and StateT in action. 
I'm hoping to get anything from a one-line response to a rewrite of my code. Anything will help.


Perhaps this is useful:
http://www.haskell.org/haskellwiki/Equational_reasoning_examples#Coding_style:_indentation_creep_with_nested_Maybe

Claus 


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


Re: [Haskell-cafe] Haskell philosophy question

2009-05-18 Thread Henning Thielemann
Vasili I. Galchin schrieb:
> Hello,
> 
>  I am confused between Haskell as delineated in the Haskell Report
> VS ghc "pragmas" which extend Haskell beyond the Haskell Report. I am
> sure I am not the first to ask. Caveat: on my part, I am not against
> innovation/extensions, but I don't like to see language "bloat". This is
> not a negative/pegorative statement  just a challenging one.

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

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


[Haskell-cafe] Re: The HP and PackedString

2009-05-18 Thread Simon Marlow

On 13/05/2009 13:07, Duncan Coutts wrote:

On Wed, 2009-05-13 at 15:37 +0400, Bulat Ziganshin wrote:

Hello Duncan,

Wednesday, May 13, 2009, 3:33:13 PM, you wrote:


I think it should remain deprecated and we should work on the
replacement so that TH can switch its dependency.

TH isn't high-performance package and i think that it should just
switch to use of String


That's a reasonable proposal for the next major release of the platform.
Please do propose it on the libraries list and see if we can get a
consensus.


I'll do the proposal - I've just made the change locally, I'll validate 
and then make a patch for comments.


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


[Haskell-cafe] fast Eucl. dist. - Haskell vs C

2009-05-18 Thread Kenneth Hoste

Hello,

For a while now, I've been trying to come up with a fast Haskell-only
function which implements Euclidean distance in n-dimensional space.

So far, I've been disappointed by the performance of my best effort
in Haskell, compared to C. I'm hoping some of the Haskell experts
and/or performance gurus on this list can help me out on resolving this,
and also maybe shed some light on some strange (imho) things I've run
into.

My current best try uses the uvector package, has two 'vectors' of type
(UArr Double)  as input, and relies on the sumU and zipWithU functions
which use streaming to compute the result:

dist_fast :: UArr Double -> UArr Double -> Double
dist_fast p1 p2 = sumDs `seq` sqrt sumDs
where
sumDs = sumU ds
ds= zipWithU euclidean p1 p2
euclidean x y = d*d
where
d = x-y

I've been benchmarking this function against various alternatives
using the MicroBench [1] package, which allows to get accurate timings  
of

single function calls.
I've also mimicked the MicroBench approach in pure C, to get comparable
timings for a C-only implementation.
The C-only function is quite straightforward:

double dist(int dim, double* p1, double* p2){

int i;
double d = 0.0;

for(i=0; i < dim; i++){
d += (p1[i] - p2[i])*(p1[i] - p2[i]);
}

return sqrt(d);
}

(Note that the optimizer takes care of the p1-p2 operation
appearing twice in the code).

All code is attached if you'd like to play around with it.

All numbers reported below are using GHC 6.10.2 and gcc 4.3.3
on Linux/x86.

The compilation details can be found in the Makefile attached, but
in short, I'm using -O2 -fexcess-precision or
-O2 -fexcess-precision -fvia-C -optc-O3 with GHC, and -O3 with gcc.



Dist.hs
Description: Binary data


microbench_dist.c
Description: Binary data


microbench_dist.hs
Description: Binary data




dist_c.c
Description: Binary data


dist_c.h
Description: Binary data


Makefile
Description: Binary data



Now the bad news: for small dimensions, e.g. 2D/3D-space,
the dist_fast function is 70-240x slower than a pure C implementation,
depending on the architecture.

For example, in 2D-space on an Intel Pentium 4 (3.0GHz, 1M L2 cache),
a single call to dist_fast takes about 1.75 microseconds (or  
0.0175s),

while a call to dist_c (C implementation of Eucl. dist), takes about
0.025 microseconds (70x slowdown).

On a Core 2 2.5GHz with 6MB L2 this maps to 1.9 and 0.008 microseconds,
resp. (i.e. 240x slower), while on a Core i7 2.66GHz with 8MB L2 the  
numbers

are 1.53 and 0.011 microseconds (i.e. 140x slower).

For larger dimensions, the gap becomes less big, but is still
worrying: 10D: 40-110x; 100D: 10-17x; >1kD: 2.5x-6x.

I'm mostly interested in the range 10D to 100D, so seeing that
Haskell is over 10x and up to 100x slower than C is kind of
making me cry.

I've tried some things to improve on this without much luck,
on the contrary:

*) Marking dist_fast for inlining makes things worse; in general
the inlined version is 2x slower for low dimensionality, and even
5x slower for larger dimensionality.
This was somewhat surprising to me...

*) In a moment of weakness, I used the Foreign Function
Interface to call the dist_c C-only implementation from Haskell.
Unfortunately, there seems to be a lot of overhead in calling
dist_c from Haskell. Most of the performance gain from using
C melts away, and sometimes the performance of the FFI'd
dist_c is 15-30% worse than the native dist_fast version
(especially at low dimensionality).

Only for the largest dimensionalities (10k-100kD), the FFI'd
version reaches the performance of the native C approach.
But, since I'm mostly interested in the 10-100D range, this is
of little use to me.

One thing I noticed is that compiling through C using
-fvia-C -optc-O3 might be a bad idea, depending on your system.

On an Intel Pentium 4 system, -fvia-C -optc-O3 was giving me
a speedup of up 70% (large dim.), while on Core 2 and Core i7
it resulted in a slowdown of 15-20% !
I was using roughly equal versions of GCC with this, i.e. a
self-bootstrapped GCC 4.3.x.


So, my question to the list if simple: how can I get better
performance out of a Haskell-only approach?
Any comments/suggestions are highly appreciated.

I'd prefer a Haskell-only approach, but my main concern is speed.
The Euclidean distance function will be used quite heavily in various  
tools.


I currently have a C-version of some of the tools, but the amount of  
code that is
needed for those tools is becoming ridiculously big. I believe using  
Haskell
will allow me to come up with a more easy to maintain code base.  
However,

I don't want to pay a huge price for this in terms of performance.

greetings,

Kenneth

[1] MicroBench: 
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/microbench

--

Kenneth Hoste
Paris research group - 

Re: [Haskell-cafe] fast Eucl. dist. - Haskell vs C

2009-05-18 Thread Claus Reinke

My current best try uses the uvector package, has two 'vectors' of type
(UArr Double)  as input, and relies on the sumU and zipWithU functions
which use streaming to compute the result:

dist_fast :: UArr Double -> UArr Double -> Double
dist_fast p1 p2 = sumDs `seq` sqrt sumDs
where
sumDs = sumU ds
ds= zipWithU euclidean p1 p2
euclidean x y = d*d
where
d = x-y


You'll probably want to make sure that 'euclidian' is specialized to
the types you need (here 'Double'), not used overloaded for 'Num a=>a'
(check -ddump-tc, or -ddump-simpl output).

After that, unrolling the fused fold loop (uvector internal) might help
a bit, but isn't there yet:

http://hackage.haskell.org/trac/ghc/ticket/3123
http://hackage.haskell.org/trac/ghc/wiki/Inlining

And even if that gets implemented, it doesn't apply directly to your
case, where the loop is in a library, but you might want to control its
unrolling in your client code. Having the loop unrolled by a default
factor (8x or so) should help for loops like this, with little computation.

Claus


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


Re: [Haskell-cafe] fast Eucl. dist. - Haskell vs C

2009-05-18 Thread Don Stewart
kenneth.hoste:
> Hello,
>
> For a while now, I've been trying to come up with a fast Haskell-only
> function which implements Euclidean distance in n-dimensional space.
>
> So far, I've been disappointed by the performance of my best effort
> in Haskell, compared to C. I'm hoping some of the Haskell experts
> and/or performance gurus on this list can help me out on resolving this,
> and also maybe shed some light on some strange (imho) things I've run
> into.
>
> My current best try uses the uvector package, has two 'vectors' of type
> (UArr Double)  as input, and relies on the sumU and zipWithU functions
> which use streaming to compute the result:
>
> dist_fast :: UArr Double -> UArr Double -> Double
> dist_fast p1 p2 = sumDs `seq` sqrt sumDs
> where
> sumDs = sumU ds
> ds= zipWithU euclidean p1 p2
> euclidean x y = d*d
> where
> d = x-y

The problem in your uvector code is the use of lists, rather than uvector
generators. Replace [1..n] with enumFromTo:

import Control.Monad
import System.Environment
import System.IO
import Data.Array.Vector

dist :: UArr Double -> UArr Double -> Double
dist p1 p2 = sumU (zipWithU euclidean p1 p2)
where
euclidean x y = d*d where d = x-y

main = do
[dim] <- map read `fmap` getArgs

print $
  dist
(enumFromToFracU 1.0 dim)
(enumFromToFracU 1.0 dim)

Now the entire thiing will fuse to a loop.

  $s$wfold_s1RR :: Double# -> Double# -> Double# -> Double#

  $s$wfold_s1RR =
\ (sc_s1RH :: Double#)
  (sc1_s1RI :: Double#)
  (sc2_s1RJ :: Double#) ->
  case >## sc1_s1RI a5_s1QR of wild4_a1tn {
False ->
  case >## sc_s1RH a5_s1QR of wild5_X1vx {
False ->
  let {
x1_a1Jg [ALWAYS Just L] :: Double#

x1_a1Jg = -## sc1_s1RI sc_s1RH } in
  $s$wfold_s1RR
(+## sc_s1RH 1.0)
(+## sc1_s1RI 1.0)
(+## sc2_s1RJ (*## x1_a1Jg x1_a1Jg));
True -> sc2_s1RJ
  };
True -> sc2_s1RJ
  }; } in
case $s$wfold_s1RR 1.0 1.0 0.0 of ww_s1QH { __DEFAULT ->
a19 (D# ww_s1QH)

and this assembly:

$ ghc -O2 -fvia-C -optc-O3

  s1T9_info:
  movsd   5(%rbx), %xmm7
  ucomisd %xmm7, %xmm6
  ja  .L15
  ucomisd %xmm7, %xmm5
  jbe .L18
.L14:
.L15:
  movsd   (%rbp), %xmm5
  leaq8(%rbp), %rbp
  jmp *(%rbp)
.L18:
  movapd  %xmm6, %xmm7
  subsd   %xmm5, %xmm7
  mulsd   %xmm7, %xmm7
  addsd   (%rbp), %xmm7
  movsd   %xmm7, (%rbp)
  movsd   .LC0(%rip), %xmm7
  addsd   %xmm7, %xmm5
  addsd   %xmm7, %xmm6
  jmp s1T9_info

Which I'd wager will match the C, which has to allocate the two arrays (GHC
essentially decides it doesn't need the arrays any more.

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


[Haskell-cafe] Trying to Express Constraints using a data structure

2009-05-18 Thread GüŸnther Schmidt

Hi all,

I'm trying to express a constraint using a data structure.

Let's say I'd want to express a "mapping" of a to b, c to b, d to b and 
e to f.


A mapping can also be from a to a, b to b and so on.

The constraint is that one cannot map a to b if b was already "mapped" 
to let's say c.


I'd like to express this constraint in a data structure, but haven't 
figured out how, yet.


Any suggestions?

Günther

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


[Haskell-cafe] Haskell in 3 Slides

2009-05-18 Thread John Van Enk
Hi all,

I'm giving a presentation to an IEEE group on Embedded DSL's and Haskell at
the end of June. I need a 3 to 4 slide introduction to Haskell. What
suggestions does the community have? Is such a short intro possible?

It just needs to introduce the basics so I can show some code without
alienating the audience. I'm hoping some one else has attempted this before,
but if not, some boiler plate slides could be useful for every one!

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


Re: [Haskell-cafe] Haskell in 3 Slides

2009-05-18 Thread Eugene Kirpichov
Just please don't show them qsort and fibonacci!

2009/5/18 John Van Enk :
> Hi all,
>
> I'm giving a presentation to an IEEE group on Embedded DSL's and Haskell at
> the end of June. I need a 3 to 4 slide introduction to Haskell. What
> suggestions does the community have? Is such a short intro possible?
>
> It just needs to introduce the basics so I can show some code without
> alienating the audience. I'm hoping some one else has attempted this before,
> but if not, some boiler plate slides could be useful for every one!
> --
> /jve
>
> ___
> 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


Re: [Haskell-cafe] Haskell in 3 Slides

2009-05-18 Thread Don Stewart
vanenkj:
> Hi all,
>  
> I'm giving a presentation to an IEEE group on Embedded DSL's and Haskell at 
> the
> end of June. I need a 3 to 4 slide introduction to Haskell. What suggestions
> does the community have? Is such a short intro possible?
>  
> It just needs to introduce the basics so I can show some code without
> alienating the audience. I'm hoping some one else has attempted this before,
> but if not, some boiler plate slides could be useful for every one!

Boil down SimonPJ's OSCON talk?

"A taste of Haskell"


http://research.microsoft.com/en-us/um/people/simonpj/papers/haskell-tutorial/index.htm
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] de-sugared code? (branch from: fast Eucl. dist. - Haskell vs C)

2009-05-18 Thread Sam Martin
Hi Don (and cafe),

Given the example you just posted, is there a simple way to generate the 
de-sugared haskell / core / STG / labelled-assembly versions of a piece of 
haskell code? For instance, how did you generate the content below? I guess 
this is the core language version?

I'm a C/C++ coder and looking for the equivalent of "Show Disassembly".

Cheers,
Sam

-Original Message-
From: haskell-cafe-boun...@haskell.org on behalf of Don Stewart
Sent: Mon 18/05/2009 14:50
To: Kenneth Hoste
Cc: Haskell Cafe mailing list
Subject: Re: [Haskell-cafe] fast Eucl. dist. - Haskell vs C
 
kenneth.hoste:
> Hello,
>
> For a while now, I've been trying to come up with a fast Haskell-only
> function which implements Euclidean distance in n-dimensional space.
>
> So far, I've been disappointed by the performance of my best effort
> in Haskell, compared to C. I'm hoping some of the Haskell experts
> and/or performance gurus on this list can help me out on resolving this,
> and also maybe shed some light on some strange (imho) things I've run
> into.
>
> My current best try uses the uvector package, has two 'vectors' of type
> (UArr Double)  as input, and relies on the sumU and zipWithU functions
> which use streaming to compute the result:
>
> dist_fast :: UArr Double -> UArr Double -> Double
> dist_fast p1 p2 = sumDs `seq` sqrt sumDs
> where
> sumDs = sumU ds
> ds= zipWithU euclidean p1 p2
> euclidean x y = d*d
> where
> d = x-y

The problem in your uvector code is the use of lists, rather than uvector
generators. Replace [1..n] with enumFromTo:

import Control.Monad
import System.Environment
import System.IO
import Data.Array.Vector

dist :: UArr Double -> UArr Double -> Double
dist p1 p2 = sumU (zipWithU euclidean p1 p2)
where
euclidean x y = d*d where d = x-y

main = do
[dim] <- map read `fmap` getArgs

print $
  dist
(enumFromToFracU 1.0 dim)
(enumFromToFracU 1.0 dim)

Now the entire thiing will fuse to a loop.

  $s$wfold_s1RR :: Double# -> Double# -> Double# -> Double#

  $s$wfold_s1RR =
\ (sc_s1RH :: Double#)
  (sc1_s1RI :: Double#)
  (sc2_s1RJ :: Double#) ->
  case >## sc1_s1RI a5_s1QR of wild4_a1tn {
False ->
  case >## sc_s1RH a5_s1QR of wild5_X1vx {
False ->
  let {
x1_a1Jg [ALWAYS Just L] :: Double#

x1_a1Jg = -## sc1_s1RI sc_s1RH } in
  $s$wfold_s1RR
(+## sc_s1RH 1.0)
(+## sc1_s1RI 1.0)
(+## sc2_s1RJ (*## x1_a1Jg x1_a1Jg));
True -> sc2_s1RJ
  };
True -> sc2_s1RJ
  }; } in
case $s$wfold_s1RR 1.0 1.0 0.0 of ww_s1QH { __DEFAULT ->
a19 (D# ww_s1QH)

and this assembly:

$ ghc -O2 -fvia-C -optc-O3

  s1T9_info:
  movsd   5(%rbx), %xmm7
  ucomisd %xmm7, %xmm6
  ja  .L15
  ucomisd %xmm7, %xmm5
  jbe .L18
.L14:
.L15:
  movsd   (%rbp), %xmm5
  leaq8(%rbp), %rbp
  jmp *(%rbp)
.L18:
  movapd  %xmm6, %xmm7
  subsd   %xmm5, %xmm7
  mulsd   %xmm7, %xmm7
  addsd   (%rbp), %xmm7
  movsd   %xmm7, (%rbp)
  movsd   .LC0(%rip), %xmm7
  addsd   %xmm7, %xmm5
  addsd   %xmm7, %xmm6
  jmp s1T9_info

Which I'd wager will match the C, which has to allocate the two arrays (GHC
essentially decides it doesn't need the arrays any more.

-- 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] de-sugared code? (branch from: fast Eucl. dist. - Haskell vs C)

2009-05-18 Thread Eugene Kirpichov
That's the output of ghc -ddump-simpl.

2009/5/18 Sam Martin :
> Hi Don (and cafe),
>
> Given the example you just posted, is there a simple way to generate the
> de-sugared haskell / core / STG / labelled-assembly versions of a piece of
> haskell code? For instance, how did you generate the content below? I guess
> this is the core language version?
>
> I'm a C/C++ coder and looking for the equivalent of "Show Disassembly".
>
> Cheers,
> Sam
>
> -Original Message-
> From: haskell-cafe-boun...@haskell.org on behalf of Don Stewart
> Sent: Mon 18/05/2009 14:50
> To: Kenneth Hoste
> Cc: Haskell Cafe mailing list
> Subject: Re: [Haskell-cafe] fast Eucl. dist. - Haskell vs C
>
> kenneth.hoste:
>> Hello,
>>
>> For a while now, I've been trying to come up with a fast Haskell-only
>> function which implements Euclidean distance in n-dimensional space.
>>
>> So far, I've been disappointed by the performance of my best effort
>> in Haskell, compared to C. I'm hoping some of the Haskell experts
>> and/or performance gurus on this list can help me out on resolving this,
>> and also maybe shed some light on some strange (imho) things I've run
>> into.
>>
>> My current best try uses the uvector package, has two 'vectors' of type
>> (UArr Double)  as input, and relies on the sumU and zipWithU functions
>> which use streaming to compute the result:
>>
>> dist_fast :: UArr Double -> UArr Double -> Double
>> dist_fast p1 p2 = sumDs `seq` sqrt sumDs
>> where
>> sumDs = sumU ds
>> ds    = zipWithU euclidean p1 p2
>> euclidean x y = d*d
>> where
>> d = x-y
>
> The problem in your uvector code is the use of lists, rather than uvector
> generators. Replace [1..n] with enumFromTo:
>
>     import Control.Monad
>     import System.Environment
>     import System.IO
>     import Data.Array.Vector
>
>     dist :: UArr Double -> UArr Double -> Double
>     dist p1 p2 = sumU (zipWithU euclidean p1 p2)
>     where
>     euclidean x y = d*d where d = x-y
>
>     main = do
>     [dim] <- map read `fmap` getArgs
>
>     print $
>   dist
>     (enumFromToFracU 1.0 dim)
>     (enumFromToFracU 1.0 dim)
>
> Now the entire thiing will fuse to a loop.
>
>   $s$wfold_s1RR :: Double# -> Double# -> Double# -> Double#
>
>   $s$wfold_s1RR =
>     \ (sc_s1RH :: Double#)
>   (sc1_s1RI :: Double#)
>   (sc2_s1RJ :: Double#) ->
>   case >## sc1_s1RI a5_s1QR of wild4_a1tn {
>     False ->
>   case >## sc_s1RH a5_s1QR of wild5_X1vx {
>     False ->
>   let {
>     x1_a1Jg [ALWAYS Just L] :: Double#
>
>     x1_a1Jg = -## sc1_s1RI sc_s1RH } in
>   $s$wfold_s1RR
>     (+## sc_s1RH 1.0)
>     (+## sc1_s1RI 1.0)
>     (+## sc2_s1RJ (*## x1_a1Jg x1_a1Jg));
>     True -> sc2_s1RJ
>   };
>     True -> sc2_s1RJ
>   }; } in
>     case $s$wfold_s1RR 1.0 1.0 0.0 of ww_s1QH { __DEFAULT ->
>     a19 (D# ww_s1QH)
>
> and this assembly:
>
>     $ ghc -O2 -fvia-C -optc-O3
>
>   s1T9_info:
>   movsd   5(%rbx), %xmm7
>   ucomisd %xmm7, %xmm6
>   ja  .L15
>   ucomisd %xmm7, %xmm5
>   jbe .L18
>     .L14:
>     .L15:
>   movsd   (%rbp), %xmm5
>   leaq    8(%rbp), %rbp
>   jmp *(%rbp)
>     .L18:
>   movapd  %xmm6, %xmm7
>   subsd   %xmm5, %xmm7
>   mulsd   %xmm7, %xmm7
>   addsd   (%rbp), %xmm7
>   movsd   %xmm7, (%rbp)
>   movsd   .LC0(%rip), %xmm7
>   addsd   %xmm7, %xmm5
>   addsd   %xmm7, %xmm6
>   jmp s1T9_info
>
> Which I'd wager will match the C, which has to allocate the two arrays (GHC
> essentially decides it doesn't need the arrays any more.
>
> -- 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
>
>



-- 
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] Re: de-sugared code? (branch from: fast Eucl. dist. - Haskell vs C)

2009-05-18 Thread Don Stewart
Yes, I use the ghc-core tool:

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ghc-core

sam.martin:
> Hi Don (and cafe),
> 
> Given the example you just posted, is there a simple way to generate the
> de-sugared haskell / core / STG / labelled-assembly versions of a piece of
> haskell code? For instance, how did you generate the content below? I guess
> this is the core language version?
> 
> I'm a C/C++ coder and looking for the equivalent of "Show Disassembly".
> 
> Cheers,
> Sam
> 
> -Original Message-
> From: haskell-cafe-boun...@haskell.org on behalf of Don Stewart
> Sent: Mon 18/05/2009 14:50
> To: Kenneth Hoste
> Cc: Haskell Cafe mailing list
> Subject: Re: [Haskell-cafe] fast Eucl. dist. - Haskell vs C
> 
> kenneth.hoste:
> > Hello,
> >
> > For a while now, I've been trying to come up with a fast Haskell-only
> > function which implements Euclidean distance in n-dimensional space.
> >
> > So far, I've been disappointed by the performance of my best effort
> > in Haskell, compared to C. I'm hoping some of the Haskell experts
> > and/or performance gurus on this list can help me out on resolving this,
> > and also maybe shed some light on some strange (imho) things I've run
> > into.
> >
> > My current best try uses the uvector package, has two 'vectors' of type
> > (UArr Double)  as input, and relies on the sumU and zipWithU functions
> > which use streaming to compute the result:
> >
> > dist_fast :: UArr Double -> UArr Double -> Double
> > dist_fast p1 p2 = sumDs `seq` sqrt sumDs
> > where
> > sumDs = sumU ds
> > ds= zipWithU euclidean p1 p2
> > euclidean x y = d*d
> > where
> > d = x-y
> 
> The problem in your uvector code is the use of lists, rather than uvector
> generators. Replace [1..n] with enumFromTo:
>
> import Control.Monad
> import System.Environment
> import System.IO
> import Data.Array.Vector
> 
> dist :: UArr Double -> UArr Double -> Double
> dist p1 p2 = sumU (zipWithU euclidean p1 p2)
> where
> euclidean x y = d*d where d = x-y
> 
> main = do
> [dim] <- map read `fmap` getArgs
> 
> print $
>   dist
> (enumFromToFracU 1.0 dim)
> (enumFromToFracU 1.0 dim)
> 
> Now the entire thiing will fuse to a loop.
> 
>   $s$wfold_s1RR :: Double# -> Double# -> Double# -> Double#
> 
>   $s$wfold_s1RR =
> \ (sc_s1RH :: Double#)
>   (sc1_s1RI :: Double#)
>   (sc2_s1RJ :: Double#) ->
>   case >## sc1_s1RI a5_s1QR of wild4_a1tn {
> False ->
>   case >## sc_s1RH a5_s1QR of wild5_X1vx {
> False ->
>   let {
> x1_a1Jg [ALWAYS Just L] :: Double#
> 
> x1_a1Jg = -## sc1_s1RI sc_s1RH } in
>   $s$wfold_s1RR
> (+## sc_s1RH 1.0)
> (+## sc1_s1RI 1.0)
> (+## sc2_s1RJ (*## x1_a1Jg x1_a1Jg));
> True -> sc2_s1RJ
>   };
> True -> sc2_s1RJ
>   }; } in
> case $s$wfold_s1RR 1.0 1.0 0.0 of ww_s1QH { __DEFAULT ->
> a19 (D# ww_s1QH)
> 
> and this assembly:
>
> $ ghc -O2 -fvia-C -optc-O3
> 
>   s1T9_info:
>   movsd   5(%rbx), %xmm7
>   ucomisd %xmm7, %xmm6
>   ja  .L15
>   ucomisd %xmm7, %xmm5
>   jbe .L18
> .L14:
> .L15:
>   movsd   (%rbp), %xmm5
>   leaq8(%rbp), %rbp
>   jmp *(%rbp)
> .L18:
>   movapd  %xmm6, %xmm7
>   subsd   %xmm5, %xmm7
>   mulsd   %xmm7, %xmm7
>   addsd   (%rbp), %xmm7
>   movsd   %xmm7, (%rbp)
>   movsd   .LC0(%rip), %xmm7
>   addsd   %xmm7, %xmm5
>   addsd   %xmm7, %xmm6
>   jmp s1T9_info
> 
> Which I'd wager will match the C, which has to allocate the two arrays (GHC
> essentially decides it doesn't need the arrays any more.
> 
> -- 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


[Haskell-cafe] RE: de-sugared code? (branch from: fast Eucl. dist. - Haskell vs C)

2009-05-18 Thread Sam Martin
Brilliant! Thanks.


-Original Message-
From: Don Stewart [mailto:d...@galois.com]
Sent: Mon 18/05/2009 16:21
To: Sam Martin
Cc: Kenneth Hoste; Haskell Cafe mailing list
Subject: Re: de-sugared code? (branch from: fast Eucl. dist. - Haskell vs C)
 
Yes, I use the ghc-core tool:

http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ghc-core

sam.martin:
> Hi Don (and cafe),
> 
> Given the example you just posted, is there a simple way to generate the
> de-sugared haskell / core / STG / labelled-assembly versions of a piece of
> haskell code? For instance, how did you generate the content below? I guess
> this is the core language version?
> 
> I'm a C/C++ coder and looking for the equivalent of "Show Disassembly".
> 
> Cheers,
> Sam
> 
> -Original Message-
> From: haskell-cafe-boun...@haskell.org on behalf of Don Stewart
> Sent: Mon 18/05/2009 14:50
> To: Kenneth Hoste
> Cc: Haskell Cafe mailing list
> Subject: Re: [Haskell-cafe] fast Eucl. dist. - Haskell vs C
> 
> kenneth.hoste:
> > Hello,
> >
> > For a while now, I've been trying to come up with a fast Haskell-only
> > function which implements Euclidean distance in n-dimensional space.
> >
> > So far, I've been disappointed by the performance of my best effort
> > in Haskell, compared to C. I'm hoping some of the Haskell experts
> > and/or performance gurus on this list can help me out on resolving this,
> > and also maybe shed some light on some strange (imho) things I've run
> > into.
> >
> > My current best try uses the uvector package, has two 'vectors' of type
> > (UArr Double)  as input, and relies on the sumU and zipWithU functions
> > which use streaming to compute the result:
> >
> > dist_fast :: UArr Double -> UArr Double -> Double
> > dist_fast p1 p2 = sumDs `seq` sqrt sumDs
> > where
> > sumDs = sumU ds
> > ds= zipWithU euclidean p1 p2
> > euclidean x y = d*d
> > where
> > d = x-y
> 
> The problem in your uvector code is the use of lists, rather than uvector
> generators. Replace [1..n] with enumFromTo:
>
> import Control.Monad
> import System.Environment
> import System.IO
> import Data.Array.Vector
> 
> dist :: UArr Double -> UArr Double -> Double
> dist p1 p2 = sumU (zipWithU euclidean p1 p2)
> where
> euclidean x y = d*d where d = x-y
> 
> main = do
> [dim] <- map read `fmap` getArgs
> 
> print $
>   dist
> (enumFromToFracU 1.0 dim)
> (enumFromToFracU 1.0 dim)
> 
> Now the entire thiing will fuse to a loop.
> 
>   $s$wfold_s1RR :: Double# -> Double# -> Double# -> Double#
> 
>   $s$wfold_s1RR =
> \ (sc_s1RH :: Double#)
>   (sc1_s1RI :: Double#)
>   (sc2_s1RJ :: Double#) ->
>   case >## sc1_s1RI a5_s1QR of wild4_a1tn {
> False ->
>   case >## sc_s1RH a5_s1QR of wild5_X1vx {
> False ->
>   let {
> x1_a1Jg [ALWAYS Just L] :: Double#
> 
> x1_a1Jg = -## sc1_s1RI sc_s1RH } in
>   $s$wfold_s1RR
> (+## sc_s1RH 1.0)
> (+## sc1_s1RI 1.0)
> (+## sc2_s1RJ (*## x1_a1Jg x1_a1Jg));
> True -> sc2_s1RJ
>   };
> True -> sc2_s1RJ
>   }; } in
> case $s$wfold_s1RR 1.0 1.0 0.0 of ww_s1QH { __DEFAULT ->
> a19 (D# ww_s1QH)
> 
> and this assembly:
>
> $ ghc -O2 -fvia-C -optc-O3
> 
>   s1T9_info:
>   movsd   5(%rbx), %xmm7
>   ucomisd %xmm7, %xmm6
>   ja  .L15
>   ucomisd %xmm7, %xmm5
>   jbe .L18
> .L14:
> .L15:
>   movsd   (%rbp), %xmm5
>   leaq8(%rbp), %rbp
>   jmp *(%rbp)
> .L18:
>   movapd  %xmm6, %xmm7
>   subsd   %xmm5, %xmm7
>   mulsd   %xmm7, %xmm7
>   addsd   (%rbp), %xmm7
>   movsd   %xmm7, (%rbp)
>   movsd   .LC0(%rip), %xmm7
>   addsd   %xmm7, %xmm5
>   addsd   %xmm7, %xmm6
>   jmp s1T9_info
> 
> Which I'd wager will match the C, which has to allocate the two arrays (GHC
> essentially decides it doesn't need the arrays any more.
> 
> -- 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] fast Eucl. dist. - Haskell vs C

2009-05-18 Thread Claus Reinke

dist_fast :: UArr Double -> UArr Double -> Double
dist_fast p1 p2 = sumDs `seq` sqrt sumDs
where
sumDs = sumU ds
ds= zipWithU euclidean p1 p2
euclidean x y = d*d
where
d = x-y


You'll probably want to make sure that 'euclidian' is specialized to
the types you need (here 'Double'), not used overloaded for 'Num a=>a'
(check -ddump-tc, or -ddump-simpl output).


Sorry about that misdirection - as it happened, I was looking at the 
tc output for 'dist_fast' (euclidean :: forall a. (Num a) => a -> a -> a), 
but the simpl output for 'dist_fast_inline' .., which uses things like 


   __inline_me ..
   case Dist.sumU (Dist.$wzipWithU ..
   GHC.Num.- @ GHC.Types.Double GHC.Float.$f9 x_aLt y_aLv 

Once I actually add a 'dist_fast_inline_caller', that indirection 
disappears in the inlined code, just as it does for dist_fast itself.


   dist_fast_inlined_caller :: UArr Double -> UArr Double -> Bool
   dist_fast_inlined_caller p1 p2 = dist_fast_inlined p1 p2 > 2

However, in the simpl output for 'dist_fast_inline_caller', the
'sumU' and 'zipWithU' still don't seem to be fused - Don?

Claus


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


Re: [Haskell-cafe] Haskell in 3 Slides

2009-05-18 Thread David Leimbach
Use an incredibly small font.

On Mon, May 18, 2009 at 8:16 AM, John Van Enk  wrote:

> Hi all,
>
> I'm giving a presentation to an IEEE group on Embedded DSL's and Haskell at
> the end of June. I need a 3 to 4 slide introduction to Haskell. What
> suggestions does the community have? Is such a short intro possible?
>
> It just needs to introduce the basics so I can show some code without
> alienating the audience. I'm hoping some one else has attempted this before,
> but if not, some boiler plate slides could be useful for every one!
>
> --
> /jve
>
> ___
> 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] fast Eucl. dist. - Haskell vs C

2009-05-18 Thread Don Stewart
claus.reinke:
>>> dist_fast :: UArr Double -> UArr Double -> Double
>>> dist_fast p1 p2 = sumDs `seq` sqrt sumDs
>>> where
>>> sumDs = sumU ds
>>> ds= zipWithU euclidean p1 p2
>>> euclidean x y = d*d
>>> where
>>> d = x-y
>>
>> You'll probably want to make sure that 'euclidian' is specialized to
>> the types you need (here 'Double'), not used overloaded for 'Num a=>a'
>> (check -ddump-tc, or -ddump-simpl output).
>
> Sorry about that misdirection - as it happened, I was looking at the tc 
> output for 'dist_fast' (euclidean :: forall a. (Num a) => a -> a -> a),  
> but the simpl output for 'dist_fast_inline' .., which uses things like 
>
>__inline_me ..
>case Dist.sumU (Dist.$wzipWithU ..
>GHC.Num.- @ GHC.Types.Double GHC.Float.$f9 x_aLt y_aLv 
>
> Once I actually add a 'dist_fast_inline_caller', that indirection  
> disappears in the inlined code, just as it does for dist_fast itself.
>
>dist_fast_inlined_caller :: UArr Double -> UArr Double -> Bool
>dist_fast_inlined_caller p1 p2 = dist_fast_inlined p1 p2 > 2
>
> However, in the simpl output for 'dist_fast_inline_caller', the
> 'sumU' and 'zipWithU' still don't seem to be fused - Don?

All the 'seq's and so on should be unnecessary, and even so, I still get
the expected fusion:

import Control.Monad
import System.Environment
import System.IO
import Data.Array.Vector

{-
dist :: UArr Double -> UArr Double -> Double
dist p1 p2 = sumU (zipWithU euclidean p1 p2)
where
euclidean x y = d*d where d = x-y
-}

main = do
[dim] <- map read `fmap` getArgs

print $
  dist_fast_inlined
(enumFromToFracU 1.0 dim)
(enumFromToFracU 1.0 dim)

dist_fast_inlined :: UArr Double -> UArr Double -> Double
{-# INLINE dist_fast_inlined #-}
dist_fast_inlined p1 p2 = sumDs `seq` sqrt sumDs
where
sumDs = sumU ds
ds= zipWithU euclidean p1 p2
euclidean x y = d*d
where
d = x-y

{-

19 RuleFired
2 /##
3 SC:$wfold0
5 int2Double#
1 map
1 mapList
3 streamU/unstreamU
2 truncate/Double->Int
1 unpack
1 unpack-list

$s$wfold_s1TB :: Double# -> Double# -> Double# -> Double#

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


Re: [Haskell-cafe] Haskell in 3 Slides

2009-05-18 Thread Donnie Jones
Use an incredibly small font AND Haskell FRP [1] to zoom and enlarge
the font as you move your mouse over the text.  ;)

1. http://en.wikipedia.org/wiki/Functional_reactive_programming
--
Donnie Jones


On Mon, May 18, 2009 at 10:56 AM, David Leimbach  wrote:
> Use an incredibly small font.
>
> On Mon, May 18, 2009 at 8:16 AM, John Van Enk  wrote:
>>
>> Hi all,
>>
>> I'm giving a presentation to an IEEE group on Embedded DSL's and Haskell
>> at the end of June. I need a 3 to 4 slide introduction to Haskell. What
>> suggestions does the community have? Is such a short intro possible?
>>
>> It just needs to introduce the basics so I can show some code without
>> alienating the audience. I'm hoping some one else has attempted this before,
>> but if not, some boiler plate slides could be useful for every one!
>> --
>> /jve
>>
>> ___
>> 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] Trying to Express Constraints using a data structure

2009-05-18 Thread Steffen Schuldenzucker
On 16:25 Mon 18 May , Gü?nther Schmidt wrote:
> Hi all,
>
> I'm trying to express a constraint using a data structure.
>
> Let's say I'd want to express a "mapping" of a to b, c to b, d to b and e 
> to f.
>
> A mapping can also be from a to a, b to b and so on.
>
> The constraint is that one cannot map a to b if b was already "mapped" to 
> let's say c.
>
> I'd like to express this constraint in a data structure, but haven't 
> figured out how, yet.

Hum, there was that paper where they developed a DSL for GPU
computations. I remember there was the problem that GPUs can't compute
"maps of maps" and they solved it using a data structure:

http://www.cse.unsw.edu.au/~chak/papers/LCGK09.html

Hope that helps.

Steffen


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


Re: [Haskell-cafe] Haskell in 3 Slides

2009-05-18 Thread Joe Fredette
While an incredibly small font is a clever option, a more serious 
suggestion may be as follows.


3-4 slides imply 3-4 topics, so the question is what are the 3-4 biggest 
topics in haskell? I would think they would be:


* Purity/Referential Transparency
* Lazy Evaluation
* Strong Typing + Type Classes
* Monads

Assuming you have, say, 10-15 minutes for the talk, and the people there 
are versed with imperative programming and maybe have some experience in 
functional programming, you can probably jump over each of those slides 
in about a minute, just enough to touch the subject.


I also assume that you don't need to fit the whole presentation in 3-4 
slides, if you do, then  yah.



/Joe


David Leimbach wrote:

Use an incredibly small font.

On Mon, May 18, 2009 at 8:16 AM, John Van Enk > wrote:


Hi all,
 
I'm giving a presentation to an IEEE group on Embedded DSL's and

Haskell at the end of June. I need a 3 to 4 slide introduction to
Haskell. What suggestions does the community have? Is such a short
intro possible?
 
It just needs to introduce the basics so I can show some code

without alienating the audience. I'm hoping some one else has
attempted this before, but if not, some boiler plate slides could
be useful for every one!

-- 
/jve


___
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
  
begin:vcard
fn:Joseph Fredette
n:Fredette;Joseph
adr:Apartment #3;;6 Dean Street;Worcester;Massachusetts;01609;United States of America
email;internet:jfred...@gmail.com
tel;home:1-508-966-9889
tel;cell:1-508-254-9901
x-mozilla-html:FALSE
url:lowlymath.net, humbuggery.net
version:2.1
end:vcard

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


Re: [Haskell-cafe] Haskell in 3 Slides

2009-05-18 Thread John Van Enk
Thanks Joe,

Your assumption is correct--the whole presentation will be longer. I wanted
to use 3 or 4 slides to introduce the language and the balance for the
interesting stuff. :P

/jve

PS to Joe: I will not forget to reply to all. I will not forget to reply to
all. I will not forget to reply to all. There, hopefully I won't forget any
more. :)

On Mon, May 18, 2009 at 12:29 PM, Joe Fredette  wrote:

> While an incredibly small font is a clever option, a more serious
> suggestion may be as follows.
>
> 3-4 slides imply 3-4 topics, so the question is what are the 3-4 biggest
> topics in haskell? I would think they would be:
>
> * Purity/Referential Transparency
> * Lazy Evaluation
> * Strong Typing + Type Classes
> * Monads
>
> Assuming you have, say, 10-15 minutes for the talk, and the people there
> are versed with imperative programming and maybe have some experience in
> functional programming, you can probably jump over each of those slides in
> about a minute, just enough to touch the subject.
>
> I also assume that you don't need to fit the whole presentation in 3-4
> slides, if you do, then  yah.
>
>
> /Joe
>
>
> David Leimbach wrote:
>
>> Use an incredibly small font.
>>
>> On Mon, May 18, 2009 at 8:16 AM, John Van Enk > vane...@gmail.com>> wrote:
>>
>>Hi all,
>>I'm giving a presentation to an IEEE group on Embedded DSL's and
>>Haskell at the end of June. I need a 3 to 4 slide introduction to
>>Haskell. What suggestions does the community have? Is such a short
>>intro possible?
>>It just needs to introduce the basics so I can show some code
>>without alienating the audience. I'm hoping some one else has
>>attempted this before, but if not, some boiler plate slides could
>>be useful for every one!
>>
>>--/jve
>>
>>___
>>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
>>
>>
>


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


Re: [Haskell-cafe] Haskell in 3 Slides

2009-05-18 Thread Andrew Wagner
Don't forget to include higher-order functions in one of those important
points.

On Mon, May 18, 2009 at 12:36 PM, John Van Enk  wrote:

> Thanks Joe,
>
> Your assumption is correct--the whole presentation will be longer. I wanted
> to use 3 or 4 slides to introduce the language and the balance for the
> interesting stuff. :P
>
> /jve
>
> PS to Joe: I will not forget to reply to all. I will not forget to reply to
> all. I will not forget to reply to all. There, hopefully I won't forget any
> more. :)
>
> On Mon, May 18, 2009 at 12:29 PM, Joe Fredette  wrote:
>
>> While an incredibly small font is a clever option, a more serious
>> suggestion may be as follows.
>>
>> 3-4 slides imply 3-4 topics, so the question is what are the 3-4 biggest
>> topics in haskell? I would think they would be:
>>
>> * Purity/Referential Transparency
>> * Lazy Evaluation
>> * Strong Typing + Type Classes
>> * Monads
>>
>> Assuming you have, say, 10-15 minutes for the talk, and the people there
>> are versed with imperative programming and maybe have some experience in
>> functional programming, you can probably jump over each of those slides in
>> about a minute, just enough to touch the subject.
>>
>> I also assume that you don't need to fit the whole presentation in 3-4
>> slides, if you do, then  yah.
>>
>>
>> /Joe
>>
>>
>> David Leimbach wrote:
>>
>>> Use an incredibly small font.
>>>
>>> On Mon, May 18, 2009 at 8:16 AM, John Van Enk >> vane...@gmail.com>> wrote:
>>>
>>>Hi all,
>>>I'm giving a presentation to an IEEE group on Embedded DSL's and
>>>Haskell at the end of June. I need a 3 to 4 slide introduction to
>>>Haskell. What suggestions does the community have? Is such a short
>>>intro possible?
>>>It just needs to introduce the basics so I can show some code
>>>without alienating the audience. I'm hoping some one else has
>>>attempted this before, but if not, some boiler plate slides could
>>>be useful for every one!
>>>
>>>--/jve
>>>
>>>___
>>>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
>>>
>>>
>>
>
>
> --
> /jve
>
> ___
> 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 in 3 Slides

2009-05-18 Thread Eugene Kirpichov
Actually, I don't think it's a good idea to introduce monads on one of
the 3-4 slides. While it *is* a core concept, it's not one of the
advertising "bullet points"; and 1 slide is not enough to show what
*use* monads are, let alone what they actually *are*.

I'd probably suggest you to show something parallelism-related on that
slide: for example, STM. Showing an "atomically do foo" and saying
"And here, we atomically do foo" may turn out impressive :)

And yes, of course HOF's.

Also, on the Strong Typing slide, probably you could fit in an
algebraic datatype and a smallish function over it in pattern-matched
style.

2009/5/18 Joe Fredette :
> While an incredibly small font is a clever option, a more serious suggestion
> may be as follows.
>
> 3-4 slides imply 3-4 topics, so the question is what are the 3-4 biggest
> topics in haskell? I would think they would be:
>
> * Purity/Referential Transparency
> * Lazy Evaluation
> * Strong Typing + Type Classes
> * Monads
>
> Assuming you have, say, 10-15 minutes for the talk, and the people there are
> versed with imperative programming and maybe have some experience in
> functional programming, you can probably jump over each of those slides in
> about a minute, just enough to touch the subject.
>
> I also assume that you don't need to fit the whole presentation in 3-4
> slides, if you do, then  yah.
>
>
> /Joe
>
>
> David Leimbach wrote:
>>
>> Use an incredibly small font.
>>
>> On Mon, May 18, 2009 at 8:16 AM, John Van Enk > > wrote:
>>
>>    Hi all,
>>        I'm giving a presentation to an IEEE group on Embedded DSL's and
>>    Haskell at the end of June. I need a 3 to 4 slide introduction to
>>    Haskell. What suggestions does the community have? Is such a short
>>    intro possible?
>>        It just needs to introduce the basics so I can show some code
>>    without alienating the audience. I'm hoping some one else has
>>    attempted this before, but if not, some boiler plate slides could
>>    be useful for every one!
>>
>>    --    /jve
>>
>>    ___
>>    Haskell-Cafe mailing list
>>    haskell-c...@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
>
>



-- 
Eugene Kirpichov
Web IR developer, market.yandex.ru
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Data.Binary and little endian encoding

2009-05-18 Thread Sven Panne
Am Sonntag, 17. Mai 2009 15:08:29 schrieb Don Stewart:
> Sven.Panne:
> > [...]
> > I think most problems can be fixed in a rather pragmatic way by adding a
> > few functions to the binary package:
> [...]
> Patches are welcome.

Attached. A few remarks:

 * This is only a quick and mildly tested implementation of the IEEE 
functions, especially NaNs, infinities and denormalized numbers are untested. 
These problems could totally be avoided if we can coerce representations 
directly, changing only their interpretation.

 * The *host functions assume an IEEE platform, but this can easily be changed 
(see comments).

 * Perhaps one can use unsafeCoerce for word32ToFloat and friends, but I 
haven't checked this.

 * I've seen a few "{- INLINE -}" comments. Is this really wanted or only a 
typo?

 * A comment about using peek/poke for the *le/*be functions is wrong, because 
this would introduce alignment constraints on some platforms.

I think the main point is to provide a nice and efficient API, hiding all the 
dirty stuff in the implementation.

> > One final remarks: I think the low level functions of the binary package
> > should really keep the notions of "endianess" and "alignment constraints"
> > separate, something which isn't done currently: The *host functions have
> > alignment restrictions, the *be/*le functions don't. There is no good
> > reason for this non-orthogonality.
>
> That seems reasonable.

There are various ways to achieve this, but the most obvious way leads to a 
combinatorial explosion of functions:

* 3 (LE/BE/host) * 2 (aligned/unaligned)

Furthermore, it would be good to split the binary package into the 2 layers 
already discussed first, then it is perhaps a bit clearer what a nice API 
would look like. I think it would be best to shift this API design discussion 
to the libraries list.

Cheers,
   S.

Only in binary-0.5.0.1: dist
diff -r -u binary-0.5.0.1.orig/src/Data/Binary/Builder.hs binary-0.5.0.1/src/Data/Binary/Builder.hs
--- binary-0.5.0.1.orig/src/Data/Binary/Builder.hs	Sat Mar  7 23:59:44 2009
+++ binary-0.5.0.1/src/Data/Binary/Builder.hs	Mon May 18 17:36:22 2009
@@ -41,20 +41,27 @@
 , putWord16be   -- :: Word16 -> Builder
 , putWord32be   -- :: Word32 -> Builder
 , putWord64be   -- :: Word64 -> Builder
+, putFloatIEEEbe-- :: Float -> Builder
+, putDoubleIEEEbe   -- :: Double -> Builder
 
 -- ** Little-endian writes
 , putWord16le   -- :: Word16 -> Builder
 , putWord32le   -- :: Word32 -> Builder
 , putWord64le   -- :: Word64 -> Builder
+, putFloatIEEEle-- :: Float -> Builder
+, putDoubleIEEEle   -- :: Double -> Builder
 
 -- ** Host-endian, unaligned writes
 , putWordhost   -- :: Word -> Builder
 , putWord16host -- :: Word16 -> Builder
 , putWord32host -- :: Word32 -> Builder
 , putWord64host -- :: Word64 -> Builder
+, putFloatIEEEhost  -- :: Float -> Builder
+, putDoubleIEEEhost -- :: Double -> Builder
 
   ) where
 
+import Prelude hiding (significand, exponent)
 import Foreign
 import Data.Monoid
 import Data.Word
@@ -360,6 +367,60 @@
 -- on a little endian machine:
 -- putWord64le w64 = writeN 8 (\p -> poke (castPtr p) w64)
 
+-- | Write a Float in IEEE big endian format
+putFloatIEEEbe :: Float -> Builder
+putFloatIEEEbe = putWord32be . floatToWord32
+{-# INLINE putFloatIEEEbe #-}
+
+-- | Write a Double in IEEE big endian format
+putDoubleIEEEbe :: Double -> Builder
+putDoubleIEEEbe = putWord64be . doubleToWord64
+{-# INLINE putDoubleIEEEbe #-}
+
+-- | Write a Float in IEEE little endian format
+putFloatIEEEle :: Float -> Builder
+putFloatIEEEle = putWord32le . floatToWord32
+{-# INLINE putFloatIEEEle #-}
+
+-- | Write a Double in IEEE little endian format
+putDoubleIEEEle :: Double -> Builder
+putDoubleIEEEle = putWord64le . doubleToWord64
+{-# INLINE putDoubleIEEEle #-}
+
+floatToWord32 :: Float -> Word32
+-- floatToWord32 = unsafeReinterpret
+floatToWord32 = encodeIEEE 8 23
+
+doubleToWord64 :: Double -> Word64
+-- doubleToWord64 = unsafeReinterpret
+doubleToWord64 = encodeIEEE 11 52
+
+-- TODO: Check if this works for denormalized numbers, NaNs and infinities.
+encodeIEEE :: (RealFloat a, Bits b, Integral b) => Int -> Int -> a -> b
+encodeIEEE exponentBits significandBits f =
+  (signBit `shiftL` (exponentBits + significandBits)) .|.
+  (exponentField `shiftL` significandBits) .|.
+  significandField
+   where (significand, exponent) = decodeFloat f
+
+ signBit | significand < 0 = 1
+ | otherwise = 0
+ exponentField | significand == 0 && exponent == 0 = 0
+   | otherwise = fromIntegral exponent + exponentBias + fromIntegral significandBits
+ significandField = fromIntegral (abs significand) .&. significandMask
+
+ exponentBias = bit (exponentBits - 1) - 1
+ significandMask = bit significa

Re: [Haskell-cafe] tips on using monads

2009-05-18 Thread Ryan Ingram
On Mon, May 18, 2009 at 3:08 AM, Neil Brown  wrote:
> With ErrorT you can use throwError when you want to break out of the
> block and give back an error, which seems to fit what you were doing.

Of course, now that you are using throwError, you can remove a lot of
the extra indentation:

> insertNote :: NoteRecord -> Connection -> IO ()
> insertNote nr conn = either putStrLn return =<< runErrorT
>  (do -- Check if it exists in the database already.
>      status <- liftIO $ checkPreExistingText nr conn
>      when status $ throwError "Skipping... text exists already."
>      -- Find best fit for all topics and source.
>      -- See type signatures below.
>      bestFitTopics <- liftIO $ fitTopics nr conn
>      bestFitSource <- liftIO $ fitSource nr conn
>      when (any isNothing bestFitTopics) $ throwError "Error... some topic 
> couldn't be matched."
>      when (isNothing bestFitSource) $ throwError "Error.. source couldn't be 
> matched."
>      b <- liftIO $ isUserOkay nr bestFitTopics bestFitSource
>      when (not b) $ throwError "Abort due to user request."
>      -- Create a new NoteRecord with matched
>      -- and validated topics/source.
>      let nrValidated = nr { recordTopics = bestFitTopics, recordSource = 
> bestFitSource }
>      liftIO $ insertRow nrValidated conn
>  )

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


Re: [Haskell-cafe] tips on using monads

2009-05-18 Thread Claus Reinke
I've got one of those algorithms which "threatens to march off the right edge" (in the words of 
Goerzen et al). I need something like a State or Maybe monad, but this is inside the IO monad. 
So I presume I need StateT or MaybeT. However, I'm still (sdlowly) learning about monads from 
first principles. I thought I might present my code and get some pointers... maybe someone could 
actually show me how to rewrite it, which would be a neat way to see MaybeT and StateT in 
action. I'm hoping to get anything from a one-line response to a rewrite of my code. Anything 
will help.


Perhaps this is useful:
http://www.haskell.org/haskellwiki/Equational_reasoning_examples#Coding_style:_indentation_creep_with_nested_Maybe
I can't quite tell--is that example in the IO monad? Part of my difficulty is that I'm inside IO. 
I know how to do this with Maybe, except that I have to combine Maybe and IO (use MaybeT?)


It was in the GHC.Conc.STM monad, so yes, it used a MaybeT
and Control.Monad.Trans.MonadTrans's lift (btw, the MonadTrans
docs only point to [1], but [2] might also be of interest, if rather
more compact/terse).

Claus

[1] http://web.cecs.pdx.edu/~mpj/pubs/springschool.html
[2] http://web.cecs.pdx.edu/~mpj/pubs/modinterp.html




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


[Haskell-cafe] ANN: Hieroglyph-2.21 and buster, buster-gtk, and buster-network-2.0

2009-05-18 Thread Jeff Heard
Tons of relevant changes.  Almost too many to count...

Buster:
- Fixed performance and bugs in buster,
- split out buster, buster-network, and buster-gtk to make it easier
to only build components of the system.
- Added new functions in buster for selection and debugging.
- Added behaviours in App.Behaviours.PrintEvents for printing only
based on Group / Source / Name
- Changed name to "ename" (for 'event name')
- Added Association Lists to the buster EData type (EAssoc, EAssocL)
- future now requires the bus to be passed as the first argument

Hieroglyph
- OpenGL-backended interactive buster is now functional and high
performance if not complete.
- Added "Dots" primitive for showing lots of points for things like scatterplots
- Got rid of creating Attributes objects in favor of modifying common
attributes with combinators; the combinators themselves have the same
name as the old attributes, but they are mostly undocumented otherwise
because I haven't had time yet.  They are found in
Graphics.Rendering.Hieroglyph.Visual
- Got rid of greater/less detail combinator
- Text now takes Text.PrettyPrint.Doc instead of String as the str,
accepts Pango markup language, and uses full Layout functionality from
Pango, including UTF-8 display.  Added Pango markup combinators for
Text.PrettyPrint.Docs, mark, bold, bigger, italic, strikethrough,
subscript, superscript, smaller, monospace, underline, and span.  See
Pango documentation for their effect.
- Points and Rects are now sensible instances of Num, Fractional, and Ord
- Large scenes are now faster overall
- Added object naming combinator to support object selection

I will have more deails and examples on the blog soon...

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


[Haskell-cafe] Re: [Haskell] [ANN] Safe Lazy IO in Haskell

2009-05-18 Thread Nicolas Pouillard
Excerpts from Jason Dusek's message of Sun May 17 15:45:25 +0200 2009:
>   From the documentation:
> 
>  "  LI could be a strict monad and a strict applicative functor.
> However it is not a lazy monad nor a lazy applicative
> functor as required Haskell. Hopefully it is a lazy
> (pointed) functor at least.

The type I would need for bind is this one:

  (>>=) :: NFData sa => LI sa -> (sa -> LI b) -> LI b

And because of the NFData constraint this type bind is less general than the
required one.

BTW this operator is exported as (!>>=) by System.IO.Lazy.Input.Extra.

By using the rmonad we could add this NFData constraint, but that's not like
having a Monad instance directly.

Best regards,

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


Re: [Haskell-cafe] Haskell in 3 Slides

2009-05-18 Thread Joe Fredette
Well, since the topic was EDSLs, and those generally involve monads (at 
least from what I've seen), it might be wise to touch on them. However, 
perhaps the fourth slide would just be a catchall? HOFs, some STM/Monad 
stuff, etc? The topics I suggested just seem to me to be the 4 core 
concepts you must understand to use haskell effectively.


/joe

Eugene Kirpichov wrote:

Actually, I don't think it's a good idea to introduce monads on one of
the 3-4 slides. While it *is* a core concept, it's not one of the
advertising "bullet points"; and 1 slide is not enough to show what
*use* monads are, let alone what they actually *are*.

I'd probably suggest you to show something parallelism-related on that
slide: for example, STM. Showing an "atomically do foo" and saying
"And here, we atomically do foo" may turn out impressive :)

And yes, of course HOF's.

Also, on the Strong Typing slide, probably you could fit in an
algebraic datatype and a smallish function over it in pattern-matched
style.

2009/5/18 Joe Fredette :
  

While an incredibly small font is a clever option, a more serious suggestion
may be as follows.

3-4 slides imply 3-4 topics, so the question is what are the 3-4 biggest
topics in haskell? I would think they would be:

* Purity/Referential Transparency
* Lazy Evaluation
* Strong Typing + Type Classes
* Monads

Assuming you have, say, 10-15 minutes for the talk, and the people there are
versed with imperative programming and maybe have some experience in
functional programming, you can probably jump over each of those slides in
about a minute, just enough to touch the subject.

I also assume that you don't need to fit the whole presentation in 3-4
slides, if you do, then  yah.


/Joe


David Leimbach wrote:


Use an incredibly small font.

On Mon, May 18, 2009 at 8:16 AM, John Van Enk mailto:vane...@gmail.com>> wrote:

   Hi all,
   I'm giving a presentation to an IEEE group on Embedded DSL's and
   Haskell at the end of June. I need a 3 to 4 slide introduction to
   Haskell. What suggestions does the community have? Is such a short
   intro possible?
   It just needs to introduce the basics so I can show some code
   without alienating the audience. I'm hoping some one else has
   attempted this before, but if not, some boiler plate slides could
   be useful for every one!

   --/jve

   ___
   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







  
begin:vcard
fn:Joseph Fredette
n:Fredette;Joseph
adr:Apartment #3;;6 Dean Street;Worcester;Massachusetts;01609;United States of America
email;internet:jfred...@gmail.com
tel;home:1-508-966-9889
tel;cell:1-508-254-9901
x-mozilla-html:FALSE
url:lowlymath.net, humbuggery.net
version:2.1
end:vcard

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


Re: [Haskell-cafe] Haskell in 3 Slides

2009-05-18 Thread Miguel Mitrofanov


On 18 May 2009, at 20:29, Joe Fredette wrote:

While an incredibly small font is a clever option, a more serious  
suggestion may be as follows.


3-4 slides imply 3-4 topics, so the question is what are the 3-4  
biggest topics in haskell? I would think they would be:


* Purity/Referential Transparency
* Lazy Evaluation
* Strong Typing + Type Classes
* Monads


I'd say monads are not of that importance; parametric polymorphism may  
be a better choice.






Assuming you have, say, 10-15 minutes for the talk, and the people  
there are versed with imperative programming and maybe have some  
experience in functional programming, you can probably jump over  
each of those slides in about a minute, just enough to touch the  
subject.


I also assume that you don't need to fit the whole presentation in  
3-4 slides, if you do, then  yah.



/Joe


David Leimbach wrote:

Use an incredibly small font.

On Mon, May 18, 2009 at 8:16 AM, John Van Enk mailto:vane...@gmail.com 
>> wrote:


   Hi all,
I'm giving a presentation to an IEEE group on Embedded  
DSL's and

   Haskell at the end of June. I need a 3 to 4 slide introduction to
   Haskell. What suggestions does the community have? Is such a short
   intro possible?
It just needs to introduce the basics so I can show some code
   without alienating the audience. I'm hoping some one else has
   attempted this before, but if not, some boiler plate slides could
   be useful for every one!

   -- /jve

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


Re: [Haskell-cafe] Haskell in 3 Slides

2009-05-18 Thread Don Stewart
jfredett:
> While an incredibly small font is a clever option, a more serious  
> suggestion may be as follows.
>
> 3-4 slides imply 3-4 topics, so the question is what are the 3-4 biggest  
> topics in haskell? I would think they would be:
>
> * Purity/Referential Transparency
> * Lazy Evaluation
> * Strong Typing + Type Classes
> * Monads

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


Re: [Haskell-cafe] Haskell in 3 Slides

2009-05-18 Thread Don Stewart
ekirpichov:
> Actually, I don't think it's a good idea to introduce monads on one of
> the 3-4 slides. While it *is* a core concept, it's not one of the
> advertising "bullet points"; and 1 slide is not enough to show what
> *use* monads are, let alone what they actually *are*.
> 
> I'd probably suggest you to show something parallelism-related on that
> slide: for example, STM. Showing an "atomically do foo" and saying
> "And here, we atomically do foo" may turn out impressive :)
> 

Exactly: focus on what the user wants to do (e.g. write multicore code,
write safe code, write code quickly), not how that is achieved:
"bounded parametric polymorphism" or "monads"
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell in 3 Slides

2009-05-18 Thread Adam Turoff
On Mon, May 18, 2009 at 2:06 PM, Don Stewart  wrote:
> Exactly: focus on what the user wants to do (e.g. write multicore code,
> write safe code, write code quickly), not how that is achieved:
> "bounded parametric polymorphism" or "monads"

Parametric polymorphism is a big win, and highlights something
a user wants to do.  A *shallow* overview (one bullet, one
function) might fit.  Off the top of my head:

  incr :: (Num a) => a -> a
  incr = (+ 1)

Writing that operation in other languages is either (a) repeated for
every numeric type or (b) not typesafe.  Haskell is one of the few
that delivers both, and that is worth underscoring.  And it gives
you an opportunity to wave your hands and talk about type
inferencing without wasting room on a slide.

Don is right.  Forget the details.  Cover the capabilities,
not the mechanics.

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


Re: [Haskell-cafe] Haskell in 3 Slides

2009-05-18 Thread Don Stewart
adam.turoff:
> On Mon, May 18, 2009 at 2:06 PM, Don Stewart  wrote:
> > Exactly: focus on what the user wants to do (e.g. write multicore code,
> > write safe code, write code quickly), not how that is achieved:
> > "bounded parametric polymorphism" or "monads"
> 
> Parametric polymorphism is a big win, and highlights something
> a user wants to do.  A *shallow* overview (one bullet, one
> function) might fit.  Off the top of my head:
> 
>   incr :: (Num a) => a -> a
>   incr = (+ 1)
> 
> Writing that operation in other languages is either (a) repeated for
> every numeric type or (b) not typesafe.  Haskell is one of the few
> that delivers both, and that is worth underscoring.  And it gives
> you an opportunity to wave your hands and talk about type
> inferencing without wasting room on a slide.
> 

Right, so talk about "Reuse!" (polymorphism) , "Productivity" (type
inference) "Performance" (static typing + optimizer)

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


Re: [Haskell-cafe] Haskell in 3 Slides

2009-05-18 Thread Eugene Kirpichov
The main bullet point is missing: Correctness.

How could we have forgotten quickcheck?

> quickCheck (\xs -> sort (sort xs) == sort xs)
OK, 100 tests passed.

2009/5/18 Don Stewart :
> adam.turoff:
>> On Mon, May 18, 2009 at 2:06 PM, Don Stewart  wrote:
>> > Exactly: focus on what the user wants to do (e.g. write multicore code,
>> > write safe code, write code quickly), not how that is achieved:
>> > "bounded parametric polymorphism" or "monads"
>>
>> Parametric polymorphism is a big win, and highlights something
>> a user wants to do.  A *shallow* overview (one bullet, one
>> function) might fit.  Off the top of my head:
>>
>>   incr :: (Num a) => a -> a
>>   incr = (+ 1)
>>
>> Writing that operation in other languages is either (a) repeated for
>> every numeric type or (b) not typesafe.  Haskell is one of the few
>> that delivers both, and that is worth underscoring.  And it gives
>> you an opportunity to wave your hands and talk about type
>> inferencing without wasting room on a slide.
>>
>
> Right, so talk about "Reuse!" (polymorphism) , "Productivity" (type
> inference) "Performance" (static typing + optimizer)
>
> -- Don
> ___
> 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


Re: [Haskell-cafe] fast Eucl. dist. - Haskell vs C

2009-05-18 Thread Claus Reinke
Once I actually add a 'dist_fast_inline_caller', that indirection  
disappears in the inlined code, just as it does for dist_fast itself.


   dist_fast_inlined_caller :: UArr Double -> UArr Double -> Bool
   dist_fast_inlined_caller p1 p2 = dist_fast_inlined p1 p2 > 2

However, in the simpl output for 'dist_fast_inline_caller', the
'sumU' and 'zipWithU' still don't seem to be fused - Don?


All the 'seq's and so on should be unnecessary, and even so, I still get
the expected fusion:


As I said, I don't get the fusion if I just add the function above to the 
original Dist.hs, export it and compile the module with '-c -O2 -ddump-simpl':


Dist.dist_fast_inlined_caller =
 \ (w1_s1nb :: Data.Array.Vector.UArr.UArr GHC.Types.Double)
   (w2_s1nc :: Data.Array.Vector.UArr.UArr GHC.Types.Double) ->
   case (Dist.$wzipWithU Dist.lvl2 w1_s1nb w2_s1nc)
`cast` (trans
  Data.Array.Vector.UArr.TFCo:R56:UArr
  Data.Array.Vector.UArr.NTCo:R56:UArr
:: Data.Array.Vector.UArr.UArr GHC.Types.Double
 ~
   Data.Array.Vector.Prim.BUArr.BUArr GHC.Types.Double)
   of _
   { Data.Array.Vector.Prim.BUArr.BUArr ipv_s1lb
ipv1_s1lc
ipv2_s1ld ->
   letrec {
 $wfold_s1nN :: GHC.Prim.Double#
-> GHC.Prim.Int#
-> GHC.Prim.Double#
 LclId
 [Arity 2
  Str: DmdType LL]
 $wfold_s1nN =
   \ (ww_s1mZ :: GHC.Prim.Double#) (ww1_s1n3 :: GHC.Prim.Int#) ->
 case GHC.Prim.==# ww1_s1n3 ipv1_s1lc of _ {
   GHC.Bool.False ->
 $wfold_s1nN
   (GHC.Prim.+##
  ww_s1mZ
  (GHC.Prim.indexDoubleArray#
 ipv2_s1ld (GHC.Prim.+# ipv_s1lb ww1_s1n3)))
   (GHC.Prim.+# ww1_s1n3 1);
   GHC.Bool.True -> ww_s1mZ
 }; } in
   case $wfold_s1nN 0.0 0 of ww_s1n7 { __DEFAULT ->
   GHC.Prim.>## (GHC.Prim.sqrtDouble# ww_s1n7) 2.0
   }
   }

Claus


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


Re: [Haskell-cafe] fast Eucl. dist. - Haskell vs C

2009-05-18 Thread Don Stewart
claus.reinke:
>>> Once I actually add a 'dist_fast_inline_caller', that indirection   
>>> disappears in the inlined code, just as it does for dist_fast itself.
>>>
>>>dist_fast_inlined_caller :: UArr Double -> UArr Double -> Bool
>>>dist_fast_inlined_caller p1 p2 = dist_fast_inlined p1 p2 > 2
>>>
>>> However, in the simpl output for 'dist_fast_inline_caller', the
>>> 'sumU' and 'zipWithU' still don't seem to be fused - Don?
>>
>> All the 'seq's and so on should be unnecessary, and even so, I still get
>> the expected fusion:
>
> As I said, I don't get the fusion if I just add the function above to the 
> original Dist.hs, export it and compile the module with '-c -O2 
> -ddump-simpl':

I can't reproduce this.

Does the complete program fragment I posted earlier yield the desired
result?

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


Re: [Haskell-cafe] fast Eucl. dist. - Haskell vs C

2009-05-18 Thread Claus Reinke
As I said, I don't get the fusion if I just add the function above to the 
original Dist.hs, export it and compile the module with '-c -O2 
-ddump-simpl':


I can't reproduce this.


Interesting. I'm using ghc 6.11.20090320 (windows), uvector-0.1.0.3. 
I attach the modified Dist.hs and its simpl output, created via:


   ghc -c Dist.hs -O2 -ddump-tc -ddump-simpl-stats -ddump-simpl > Dist.dumps

Perhaps others can confirm the effect? Note that the 'dist_fast' in the 
same module does get fused, so it is not likely an options issue. I still 
suspect that the inlining of the 'Dist.zipWith' wrapper in the 'dist_fast_inlined'

'__inline_me' has some significance - it is odd to see inlined code in an
'__inline_me' and the fusion rule won't trigger on 'Dist.sumU . 
Dist.$wzipWithU',
right?


Does the complete program fragment I posted earlier yield the desired
result?


Yes. Note that the original poster also reported slowdown from
use of 'dist_fast_inlined'.

Claus



Dist.dumps
Description: Binary data


Dist.hs
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell in 3 Slides

2009-05-18 Thread Ryan Ingram
On Mon, May 18, 2009 at 11:33 AM, Eugene Kirpichov  wrote:
> The main bullet point is missing: Correctness.
>
> How could we have forgotten quickcheck?
>
>> quickCheck (\xs -> sort (sort xs) == sort xs)
> OK, 100 tests passed.

I like this, but given that you have a whole slide, I might write this:

isSorted :: Ord a => [a] -> Bool
isSorted [] = True
isSorted [x] = True
isSorted (x:y:rest) = x <= y && isSorted (y:rest)

> quickCheck (\xs -> isSorted (sort xs))
OK, 100 tests passed.

Or, if you want to lead into a talk about fusion and/or higher order functions:

isSorted [] = True
isSorted (x:xs) = snd $ foldl' check (head x, True) xs where
check (prevElem, restSorted) thisElem = (thisElem, prevElem <=
thisElem && restSorted)

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


[Haskell-cafe] Re: [Haskell] [ANN] Safe Lazy IO in Haskell

2009-05-18 Thread Taral
On Mon, May 18, 2009 at 10:30 AM, Nicolas Pouillard
 wrote:
> The type I would need for bind is this one:
>
>  (>>=) :: NFData sa => LI sa -> (sa -> LI b) -> LI b

Will this do?

(>>=) :: (NFData sa, NFData b) => LI sa -> (sa -> LI b) -> LI b

-- 
Taral 
"Please let me know if there's any further trouble I can give you."
-- Unknown
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] old Hugs libraries?

2009-05-18 Thread Vasili I. Galchin
Hello,

  Do newSTArray, readSTArray, writeSTArray, etc. belong to an old
deprecated Hugs library/module? If so, what is the Haskell 98 replacement?

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


[Haskell-cafe] showing a user defined type

2009-05-18 Thread michael rice
I've been playing around with "The Little MLer" (pg. 95, 96) to try to improve 
my understanding of types.

I can ask ML:
 
- ints(0);
val it = Link (1,fn) : chain
-

and Haskell:

*Main> :t ints 0
ints 0 :: Chain
*Main> ints 0

:1:0:
    No instance for (Show Chain)
  arising from a use of `print' at :1:0-5
    Possible fix: add an instance declaration for (Show Chain)
    In a stmt of a 'do' expression: print it
*Main> 

I think I need to write a show function for type Chain but not
sure how to proceed.

Michael

===

;;ML

datatype chain =
  Link of (int * (int -> chain))

fun ints(n)
  = Link(n + 1, ints)

;;Haskell

data Chain = Link Int (Int -> Chain)

ints :: Int -> Chain
ints n = Link (n+1) ints




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


[Haskell-cafe] showing a user defined type

2009-05-18 Thread michael rice
I've been playing around with "The Little MLer" (pg. 95, 96) to try to improve 
my understanding of types.

I can ask ML:
 
- ints(0);
val it = Link (1,fn) : chain
-

and Haskell:

*Main> :t ints 0
ints 0 :: Chain
*Main> ints 0

:1:0:
    No instance for (Show Chain)
  arising from a use of `print' at :1:0-5
    Possible fix: add an instance declaration for (Show Chain)
    In a stmt of a 'do' expression: print it
*Main> 

I think I need to write a show function for type Chain but not
sure how to proceed.

Michael

===

;;ML

datatype chain =
  Link of (int * (int -> chain))

fun ints(n)
  = Link(n + 1, ints)

;;Haskell

data Chain = Link Int (Int -> Chain)

ints :: Int -> Chain
ints n = Link (n+1) ints




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


Re: [Haskell-cafe] old Hugs libraries?

2009-05-18 Thread Brandon S. Allbery KF8NH

On May 18, 2009, at 18:34 , Vasili I. Galchin wrote:
  Do newSTArray, readSTArray, writeSTArray, etc. belong to an  
old deprecated Hugs library/module? If so, what is the Haskell 98  
replacement?



My understanding is they should be in the provided STArray module.

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




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


Re: [Haskell-cafe] showing a user defined type

2009-05-18 Thread Brandon S. Allbery KF8NH

On May 18, 2009, at 21:19 , michael rice wrote:

*Main> :t ints 0
ints 0 :: Chain
*Main> ints 0

:1:0:
No instance for (Show Chain)



In general, you want to append

deriving Show

to your types.  You may also want to be able to input them in ghci, so  
instead say


deriving (Show, Read)

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




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


Re: [Haskell-cafe] showing a user defined type

2009-05-18 Thread Ryan Ingram
Unfortunately, you can't derive Show on Chain as defined, because it
contains a function:

> data Chain = Link Int (Int -> Chain)

You can write this:

> instance Show Chain where
>show (Link n _) = "Link " ++ show n ++ " "

Or you can make a dummy "Show" instance for functions:

> instance Show (a -> b) where show _ = ""
> data Chain = Link Int (Int -> Chain) deriving Show

One question: Do you expect to ever call the function with a different
value?  For example:

otherChain :: Chain
otherChain = case (ints 0) of Link _ f -> f 100

If not, you can replace Chain entirely by [Int], due to laziness,
something that's not possible in ML.  (Although you can get the same
result in ML by using (int * (() -> chain)) instead.

  -- ryan

On Mon, May 18, 2009 at 6:36 PM, Brandon S. Allbery KF8NH
 wrote:
> On May 18, 2009, at 21:19 , michael rice wrote:
>
> *Main> :t ints 0
> ints 0 :: Chain
> *Main> ints 0
>
> :1:0:
>     No instance for (Show Chain)
>
> In general, you want to append
>     deriving Show
> to your types.  You may also want to be able to input them in ghci, so
> instead say
>     deriving (Show, Read)
> --
> brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
> system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
> electrical and computer engineering, carnegie mellon university    KF8NH
>
>
> ___
> 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] showing a user defined type

2009-05-18 Thread David Menendez
On Mon, May 18, 2009 at 10:02 PM, Ryan Ingram  wrote:
> Unfortunately, you can't derive Show on Chain as defined, because it
> contains a function:

Sure you can. I just tried the following, and it compiled without complaints.

> import Text.Show.Functions
>
> data Chain = Link Int (Int -> Chain) deriving (Show)

The usual warnings about orphan instances apply, but the purpose of
the Text.Show.Functions module is to provide a standard Show instance
for functions so that libraries (e.g., QuickCheck) don't declare
conflicting instances.

-- 
Dave Menendez 

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


Re: [Haskell-cafe] old Hugs libraries?

2009-05-18 Thread David Menendez
On Mon, May 18, 2009 at 6:34 PM, Vasili I. Galchin  wrote:
> Hello,
>
>   Do newSTArray, readSTArray, writeSTArray, etc. belong to an old
> deprecated Hugs library/module? If so, what is the Haskell 98 replacement?

I don't know about Haskell 98, but I think the modern solution is to
use newArray, readArray, and writeArray from Data.Array.MArray.

There are more details at .

-- 
Dave Menendez 

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


RE: [Haskell-cafe] Request for feedback: HaskellDB + HList

2009-05-18 Thread Brian Bloniarz


_
Insert movie times and more without leaving Hotmail®.
http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd1_052009___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] old Hugs libraries?

2009-05-18 Thread Vasili I. Galchin
thank to all respondents!

Vasili

On Mon, May 18, 2009 at 9:41 PM, David Menendez  wrote:

> On Mon, May 18, 2009 at 6:34 PM, Vasili I. Galchin 
> wrote:
> > Hello,
> >
> >   Do newSTArray, readSTArray, writeSTArray, etc. belong to an old
> > deprecated Hugs library/module? If so, what is the Haskell 98
> replacement?
>
> I don't know about Haskell 98, but I think the modern solution is to
> use newArray, readArray, and writeArray from Data.Array.MArray.
>
> There are more details at .
>
> --
> Dave Menendez 
> >
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Lawvere papers

2009-05-18 Thread Vasili I. Galchin
Hello,

  I know that some Lawvere papers are available on TAC, but is there a
list of all Lawvere papers online and where?

Kind regards,

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


Re: [Haskell-cafe] Re: [Haskell] [ANN] Safe Lazy IO in Haskell

2009-05-18 Thread Ryan Ingram
On Mon, May 18, 2009 at 3:05 PM, Taral  wrote:
> Will this do?
>
> (>>=) :: (NFData sa, NFData b) => LI sa -> (sa -> LI b) -> LI b

No, the problem is that >>= on monads has no constraints, it must have the type
> LI a -> (a -> LI b) -> LI b

This is a common problem with trying to use do-notation; there are
some cases where you can't make the object an instance of Monad.  The
same problem holds for Data.Set; you'd can write

setBind :: Ord b => Set a -> (a -> Set b) -> Set b
setBind m f = unions (map f $ toList m)

but there is no way to use setBind for a definition of >>=

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


[Haskell-cafe] How to use Data.ByteString ?

2009-05-18 Thread z_axis
Hi, friends
the following function works well
rollDice n = getStdRandom (randomR (1,n)) :: IO Int

now i want to use /dev/random to produce better random number, but it doesnot 
work
rollDice_t n = do
hd <- openFile "/dev/random" ReadMode
v <-  B.hGet hd 1
return (v `mod` n) + 1

 No instance for (Integral B.ByteString)
  arising from a use of `mod' at Money.hs:15:12-20
Possible fix:
  add an instance declaration for (Integral B.ByteString)
In the first argument of `return', namely `(v `mod` n)'
In the first argument of `(+)', namely `return (v `mod` n)'
In the expression: return (v `mod` n) + 1

then how to use the ByteString properly ?

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


Re: [Haskell-cafe] How to use Data.ByteString ?

2009-05-18 Thread Brandon S. Allbery KF8NH

On May 19, 2009, at 01:07 , z_axis wrote:

rollDice_t n = do
hd <- openFile "/dev/random" ReadMode
v <-  B.hGet hd 1
return (v `mod` n) + 1

 No instance for (Integral B.ByteString)


You can't just read a binary string and have it interpreted as a  
number; you want to use Data.Binary to extract an Int (or whatever)  
from the ByteString.  The same would apply with legacy Strings; in  
Haskell, String, ByteString, and Int are distinct types and there is  
no automatic casting.  In fact I'm not quite sure why you thought that  
should work; even Perl would make you unpack(), and C would require  
you to use an appropriately-aligned buffer and unsafely cast the (char  
*) to an (int *).


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




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


Re: [Haskell-cafe] How to use Data.ByteString ?

2009-05-18 Thread Thomas DuBuisson
On Mon, May 18, 2009 at 10:13 PM, Brandon S. Allbery KF8NH
 wrote:
> On May 19, 2009, at 01:07 , z_axis wrote:
>
> rollDice_t n = do
>     hd <- openFile "/dev/random" ReadMode
>     v <-  B.hGet hd 1
>     return (v `mod` n) + 1
>
>  No instance for (Integral B.ByteString)
>
> You can't just read a binary string and have it interpreted as a number; you
> want to use Data.Binary to extract an Int (or whatever) from the ByteString.
>  The same would apply with legacy Strings; in Haskell, String, ByteString,
> and Int are distinct types and there is no automatic casting.  In fact I'm
> not quite sure why you thought that should work; even Perl would make you
> unpack(), and C would require you to use an appropriately-aligned buffer and
> unsafely cast the (char *) to an (int *).

More so, you appear to only be getting one byte from your random
number source, so that really limits the range of numbers this
function can produce.

Also, the error you are getting is more to do with ambigious types
because there is a typeclass implied and you didn't add any type
annotations yourself.

Suggestions:
1) Use Data.ByteString.Lazy
2) Read the file, and don't forget to close it - or rework how you
intend to get randoms (a better solution!)
3) Use 'decode' form Data.Binary and add a type signature to get an
Int, Word32, or some such.
4) Apply mod and return

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


Re: [Haskell-cafe] How to use Data.ByteString ?

2009-05-18 Thread Jason Dagit
On Mon, May 18, 2009 at 10:13 PM, Brandon S. Allbery KF8NH
 wrote:
> On May 19, 2009, at 01:07 , z_axis wrote:
>
> rollDice_t n = do
>     hd <- openFile "/dev/random" ReadMode
>     v <-  B.hGet hd 1
>     return (v `mod` n) + 1
>
>  No instance for (Integral B.ByteString)
>
> You can't just read a binary string and have it interpreted as a number; you
> want to use Data.Binary to extract an Int (or whatever) from the ByteString.
>  The same would apply with legacy Strings; in Haskell, String, ByteString,
> and Int are distinct types and there is no automatic casting.  In fact I'm
> not quite sure why you thought that should work; even Perl would make you
> unpack(), and C would require you to use an appropriately-aligned buffer and
> unsafely cast the (char *) to an (int *).

I just want to add that, this wouldn't stop Visual Basic!

I've often seen this bit of scary code in VB:
Dim i as Integer = 5
If i = "5" Then
   ' Do something, because 5 = "5"
End If

The designers of VB were quite odd though.  I frequently find that VB
violates the assumptions I make about programming languages (the
logical "And" operation isn't short-circuit logic!).

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


Re: [Haskell-cafe] Re: [Haskell] [ANN] Safe Lazy IO in Haskell

2009-05-18 Thread Miguel Mitrofanov


On 19 May 2009, at 09:06, Ryan Ingram wrote:


This is a common problem with trying to use do-notation; there are
some cases where you can't make the object an instance of Monad.  The
same problem holds for Data.Set; you'd can write

setBind :: Ord b => Set a -> (a -> Set b) -> Set b
setBind m f = unions (map f $ toList m)

but there is no way to use setBind for a definition of >>=


You can use a continuation trick.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Expression parsing problem

2009-05-18 Thread leledumbo

I'm writing a paper as a replacement for writing exam and decided to write
a simple compiler (got a little experience with it). However, I got trouble
in parsing expression.

The grammar:
expression  = "get" | [ "+" | "-" ] term { ( "+" | "-" ) term }
  term  = factor { ( "*" | "/" ) factor }
factor  = IDENTIFIER | VALUE | "(" expression ")"

I can't make term parse, for instance "1 * 2 / 3" (the number is not
important,
identifier is also accepted). It stops after parsing 2, i.e. only the first
multiplication is parsed. Interchanging * and / gives the same result, only
differs in operation. Whichever got encountered first will be parsed.

The same problem also arises from expression, where it can't parse "1 + 2 -
3".
Both problems are identical, but I can't figure out what's wrong (don't
count
the optional +/- before term in expression, I haven't done it yet).

Sorry, but I'm lack of knowledge about Monad. I know it can be done better
with it,
but I need to learn a lot about it, while I don't have enough time (only 2
weeks).

Below are necessary definitions for the parser (some taken from the
scanner).

For testing purpose, please try:
expression
[("1",Value),("+",Plus),("2",Value),("-",Minus),("3",Value),("EOF",EOF)]
term
[("1",Value),("*",Times),("2",Value),("/",Slash),("3",Value),("EOF",EOF)]
expression
[("1",Value),("-",Minus),("2",Value),("+",Plus),("3",Value),("EOF",EOF)]
term
[("1",Value),("/",Slash),("2",Value),("*",Times),("3",Value),("EOF",EOF)]

> data Token = Identifier | OpenBlock | CloseBlock | SemiColon | Slash |
>Equals   | OpenBrace | CloseBrace |   Minus   | Times |
> Plus|Nil|   Value|Var| Const |
> Put |Get|   Comma|EOF
>  deriving (Show,Eq)

> type Symbol = (String,Token)
> type ASL= [Symbol]


> type ParseFunc = ASL -> (ASL,[String])

> expression :: ParseFunc
> expression (h:s)
>   | snd h == Get   = (s,["IN"])
>   | op `elem` [Plus,Minus] = (s2,r1 ++ r2 ++ [operation op])
>   | otherwise  = (s1,r1)
>   where (s1,r1) = term (h:s)
> (s2,r2) = term $ tail s1
> op  = if s1 /= [] then snd $ head s1 else Nil
> expression s= (s,[])

> term :: ParseFunc
> term s = if op `elem` [Times,Slash]
>   then (s2,r1 ++ r2 ++ [operation op])
>   else (s1,r1)
>   where (s1,r1) = factor s
> (s2,r2) = factor $ tail s1
> op  = if s1 /= [] then snd $ head s1 else Nil

> factor :: ParseFunc
> factor ((id,Identifier):s) = (s,["LOAD " ++ id])
> factor ((val,Value):s) = (s,["PUSH " ++ val])
> factor (("(",OpenBrace):s) = if head s1 == (")",CloseBrace)
>   then (tail s1,r1)
>   else error $ "\")\" expected, got" ++ (show $ fst $ head s1)
>   where (s1,r1) = expression s
> factor s = (s,[])

-- 
View this message in context: 
http://www.nabble.com/Expression-parsing-problem-tp23610457p23610457.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] Re: [Haskell] [ANN] Safe Lazy IO in Haskell

2009-05-18 Thread Jason Dusek
2009/05/18 Miguel Mitrofanov :
> On 19 May 2009, at 09:06, Ryan Ingram wrote:
>
>> This is a common problem with trying to use do-notation; there are
>> some cases where you can't make the object an instance of Monad.  The
>> same problem holds for Data.Set; you'd can write
>>
>> setBind :: Ord b => Set a -> (a -> Set b) -> Set b
>> setBind m f = unions (map f $ toList m)
>>
>> but there is no way to use setBind for a definition of >>=
>
> You can use a continuation trick.

  Trick?

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


Re: [Haskell-cafe] Re: [Haskell] [ANN] Safe Lazy IO in Haskell

2009-05-18 Thread Taral
On Mon, May 18, 2009 at 10:06 PM, Ryan Ingram  wrote:
> On Mon, May 18, 2009 at 3:05 PM, Taral  wrote:
>> Will this do?
>>
>> (>>=) :: (NFData sa, NFData b) => LI sa -> (sa -> LI b) -> LI b
>
> No, the problem is that >>= on monads has no constraints, it must have the 
> type
>> LI a -> (a -> LI b) -> LI b

I'm pretty sure you can do something like:

newtype LIMonad x = NFData x => LI x

-- 
Taral 
"Please let me know if there's any further trouble I can give you."
-- Unknown
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to use Data.ByteString ?

2009-05-18 Thread Brandon S. Allbery KF8NH

On May 19, 2009, at 01:42 , Jason Dagit wrote:

I've often seen this bit of scary code in VB:
Dim i as Integer = 5
If i = "5" Then
  ' Do something, because 5 = "5"
End If


Sure, that works in Perl too.  But the equivalent case here would be  
chr$(5), not "5".


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




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