Re: [Haskell-cafe] Poll: Do you want a mascot?

2011-12-01 Thread Paulo J. Matos

Yes

On 23/11/11 19:11, heathmatlock wrote:

Question: Do you want a mascot?

Answers:
Yes
No


--
This is an attempt to figure out if this idea is going anywhere.


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



--
PMatos


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


[Haskell-cafe] Cairo and Haskell

2011-04-15 Thread Paulo J. Matos

Hi,

I would like to use Haskell to generate automatically a poster.
I guess that would be using Cairo so I can have a 2d canvas to draw in 
and maybe even preview before exporting to PDF.


However, I can't find any documentation on Cairo with Haskell or any 
code examples related to what I want to do.


Any suggestions?

Cheers,

--
PMatos


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


Re: [Haskell-cafe] Cairo and Haskell

2011-04-15 Thread Paulo J. Matos

Thanks I will take a look at those.

On 15/04/11 15:12, Robert Wills wrote:

Have a look at

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

and

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





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


Re: [Haskell-cafe] Cairo and Haskell

2011-04-15 Thread Paulo J. Matos

On 15/04/11 15:19, Chris Smith wrote:

To answer my own email, yes, PDF support is there.



Great, I assume it would also allow me to preview it on a GTK canvas, right?

--
PMatos


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


Re: [Haskell-cafe] Cairo and Haskell

2011-04-15 Thread Paulo J. Matos

On 15/04/11 16:13, John Obbele wrote:


bash $ mkdir /tmp/uncabal  cd /tmp/uncabal
bash $ cabal unpack cairo
bash $ cd /tmp/uncabal/cairo-*/demo
bash $ runghc StarAndRing.hs

The gtk2hs bindings are generaly pretty dumb and just mimic the
original C behaviour. So the best source of documentation is
the original cairo website:
 http://cairographics.org/documentation/


Awesome, just tried it and it worked! Will start off based on that! :)

--
PMatos


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


[Haskell-cafe] Installing agda through cabal

2009-06-19 Thread Paulo J. Matos
Hi all,

I am trying to install agda through cabal but I get this:
$ cabal install alex
Resolving dependencies...
[1 of 1] Compiling Main
( /tmp/alex-2.3.116333/alex-2.3.1/Setup.lhs, 
/tmp/alex-2.3.116333/alex-2.3.1/dist/setup/Main.o )

/tmp/alex-2.3.116333/alex-2.3.1/Setup.lhs:6:51:
Warning: In the use of `buildVerbose'
 (imported from Distribution.Simple.Setup):
 Deprecated: Use buildVerbosity instead

/tmp/alex-2.3.116333/alex-2.3.1/Setup.lhs:7:51:
Warning: In the use of `defaultUserHooks'
 (imported from Distribution.Simple):
 Deprecated: Use simpleUserHooks or autoconfUserHooks,
unless you need Cabal-1.2
 compatibility in which case you must stick with
defaultUserHooks
Linking /tmp/alex-2.3.116333/alex-2.3.1/dist/setup/setup ...
Warning: defaultUserHooks in Setup script is deprecated.
Configuring alex-2.3.1...
Preprocessing executables for alex-2.3.1...
Building alex-2.3.1...
[ 1 of 16] Compiling Set  ( src/Set.hs,
dist/build/alex/alex-tmp/Set.o )
[ 2 of 16] Compiling DFS  ( src/DFS.hs,
dist/build/alex/alex-tmp/DFS.o )
[ 3 of 16] Compiling Sort ( src/Sort.hs,
dist/build/alex/alex-tmp/Sort.o )
[ 4 of 16] Compiling CharSet  ( src/CharSet.hs,
dist/build/alex/alex-tmp/CharSet.o )
[ 5 of 16] Compiling Map  ( src/Map.hs,
dist/build/alex/alex-tmp/Map.o )
[ 6 of 16] Compiling Paths_alex
( dist/build/autogen/Paths_alex.hs,
dist/build/alex/alex-tmp/Paths_alex.o )
[ 7 of 16] Compiling Util ( src/Util.hs,
dist/build/alex/alex-tmp/Util.o )
[ 8 of 16] Compiling AbsSyn   ( src/AbsSyn.hs,
dist/build/alex/alex-tmp/AbsSyn.o )
[ 9 of 16] Compiling ParseMonad   ( src/ParseMonad.hs,
dist/build/alex/alex-tmp/ParseMonad.o )
[10 of 16] Compiling Scan
( dist/build/alex/alex-tmp/Scan.hs, dist/build/alex/alex-tmp/Scan.o )
[11 of 16] Compiling Output   ( src/Output.hs,
dist/build/alex/alex-tmp/Output.o )
[12 of 16] Compiling Info ( src/Info.hs,
dist/build/alex/alex-tmp/Info.o )
[13 of 16] Compiling NFA  ( src/NFA.hs,
dist/build/alex/alex-tmp/NFA.o )
[14 of 16] Compiling DFA  ( src/DFA.hs,
dist/build/alex/alex-tmp/DFA.o )
[15 of 16] Compiling Parser
( dist/build/alex/alex-tmp/Parser.hs,
dist/build/alex/alex-tmp/Parser.o )
[16 of 16] Compiling Main ( src/Main.hs,
dist/build/alex/alex-tmp/Main.o )
Linking dist/build/alex/alex ...
Installing executable(s) in /home/pmatos/.cabal/bin
pma...@drserver ~ $ cabal install agda
Resolving dependencies...
Configuring Agda-2.2.2...
cabal: alex version =2.0.1  3 is required but it could not be found.
cabal: Error: some packages failed to install:
Agda-2.2.2 failed during the configure step. The exception was:
exit: ExitFailure 1

As you can see, I had just finished installing alex 2.3.1, so why does
cabal still request alex =2.0.1  3?

Cheers,

Paulo Matos

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


Re: [Haskell-cafe] Installing agda through cabal

2009-06-19 Thread Paulo J. Matos
On Fri, 2009-06-19 at 15:35 -0500, Jake McArthur wrote:
 Paulo J. Matos wrote:
  As you can see, I had just finished installing alex 2.3.1, so why does
  cabal still request alex =2.0.1  3?
 
 Probably you don't have alex in your PATH.
 
 - Jake

Shouldn't cabal make sure the library it installs are in PATH? or at
least, they are in the PATH of the apps built by cabal itself?

Cheers,

Paulo Matos

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


Re: [Haskell-cafe] Installing agda through cabal

2009-06-19 Thread Paulo J. Matos
On Fri, 2009-06-19 at 23:35 +0200, Max Rabkin wrote:
 On Fri, Jun 19, 2009 at 11:20 PM, Paulo J. Matospocma...@gmail.com wrote:
  Shouldn't cabal make sure the library it installs are in PATH?
 
 This would require modifying the path (since there may be no writable
 location on the existing path). But the PATH is set by a combination
 of several programs written in Turing-complete languages (shell
 script), and those programs themselves are in unknown locations
 (depending on the shell in use).
 
  or at
  least, they are in the PATH of the apps built by cabal itself?
 
 This is a possibility. But surely you're one day going to want to run
 your cabal-installed programs yourself (there are some pretty handy
 ones), so the easiest thing is to extend your path.
 

You're right. Added .cabal/bin to path and everything is ok.

 It might be a good idea for cabal-install to warn that its bin
 directory is not in your path when you install an executable.
 

Yep, might be an interesting idea for warning. :)

 --Max

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


Re: [Haskell-cafe] Verifying Haskell Programs

2009-02-03 Thread Paulo J. Matos
On Mon, Feb 2, 2009 at 10:04 PM, Don Stewart d...@galois.com wrote:
 pocmatos:
 Hi all,

 Much is talked that Haskell, since it is purely functional is easier 
 to be verified.   However, most of the research I have seen in software
 verification  (either through model checking or theorem proving)
 targets C/C++ or  subsets of these. What's the state of the art of
 automatically  verifying properties of programs written in Haskell?


 State of the art is translating subsets of Haskell to Isabelle, and
 verifying them. Using model checkers to verify subsets, or extracting
 Haskell from Agda or Coq.


Any references to publications related to this?

 -- Don




-- 
Paulo Jorge Matos - pocmatos at gmail.com
Webpage: http://www.personal.soton.ac.uk/pocm
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Verifying Haskell Programs

2009-02-03 Thread Paulo J. Matos
On Tue, Feb 3, 2009 at 12:28 AM, Don Stewart d...@galois.com wrote:
 dbueno:
 On Mon, Feb 2, 2009 at 15:04, Don Stewart d...@galois.com wrote:
  pocmatos:
  Hi all,
 
  Much is talked that Haskell, since it is purely functional is easier 
  to be verified.   However, most of the research I have seen in software
  verification  (either through model checking or theorem proving)
  targets C/C++ or  subsets of these. What's the state of the art of
  automatically  verifying properties of programs written in Haskell?
 
 
  State of the art is translating subsets of Haskell to Isabelle, and
  verifying them. Using model checkers to verify subsets, or extracting
  Haskell from Agda or Coq.

 Don, can you give some pointers to literature on this, if any?  That
 is, any documentation of a verification effort of Haskell code with
 Isabelle, model checkers, or Coq?

 (It's not that I don't believe you -- I'd be really interested to read it!)


 All on haskell.org,


 http://haskell.org/haskellwiki/Research_papers/Testing_and_correctness#Verifying_Haskell_programs

 And there's been work since I put that list together.


Opps, sorry, missed this message. Should read everything before replying! :)

 -- Don




-- 
Paulo Jorge Matos - pocmatos at gmail.com
Webpage: http://www.personal.soton.ac.uk/pocm
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Verifying Haskell Programs

2009-02-01 Thread Paulo J. Matos
Hi all,

Much is talked that Haskell, since it is purely functional is easier
to be verified.
However, most of the research I have seen in software verification
(either through model checking or theorem proving) targets C/C++ or
subsets of these. What's the state of the art of automatically
verifying properties of programs written in Haskell?

Cheers,

-- 
Paulo Jorge Matos - pocmatos at gmail.com
Webpage: http://www.personal.soton.ac.uk/pocm
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] IO () and IO [()]

2008-03-10 Thread Paulo J. Matos
Hello all,

I find it funny that IO () is different from IO [()].
For example, if I define a function to output some lines with mapT, I would do:
outputLines :: Int - IO ()
outputLines i = mapM (putStrLn . show) (take i $ iterate ((+) 1) 1)

However, this is in fact
outputLines :: Int - IO [()]

I would like to know if in fact there's any difference in practice
between (), [()], i.e. if in practice the difference matters.
My first guess is that this is just a consequence of the Haskell type
system and so that everything fits this really needs to be like this.
Because
mapM :: (Monad m) = (a - m b) - [a] - m [b]

So I guess that it makes sense that you get IO [()] instead of IO (),
and adding an exception just to say that [()] == () isn't good.
By the way, as a consequence can you possibly get IO (()) or IO ([()])
and are these all different from each other?

Cheers,

-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
Sponsor ECS runners - Action against Hunger:
http://www.justgiving.com/ecsrunslikethewind
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Internships at GHC HQ

2008-02-09 Thread Paulo J. Matos
On Jan 25, 2008 11:40 AM, Simon Peyton-Jones [EMAIL PROTECTED] wrote:
 Would you be interested in working at Microsoft Research for three months?  
 If so, you might want to think about applying for an internship.

 Simon and I are looking for interns, starting in summer 2008.  Lots of 
 background info here:
 http://hackage.haskell.org/trac/ghc/wiki/Internships
 including a bunch of possible projects, although you may also have ideas of 
 your own.


Hello Simon,

I wonder if there is any interest by the part of Microsoft and the
Haskell community in a software model checker using SAT-based
techniques for Haskell.
There's have been in the last few year a couple of approaches on this
for C by several people, including some Microsoft people.

Cheers,

Paulo Matos

 But the bottom line is
 - apply by end Feb 2008 for this round
 - tell one of us that you have done so

 (None of this is restricted to Haskell stuff.  You can apply to work at any 
 Microsoft Research lab, on any topic.  But there are a lot of applicants, so 
 you are more likely to be successful if you are fairly specific about who at 
 MSR you'd like to work with and why, and contact that person to say that 
 you've applied.)

 Simon
 ___
 Glasgow-haskell-users mailing list
 [EMAIL PROTECTED]
 http://www.haskell.org/mailman/listinfo/glasgow-haskell-users






-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Comments on reading two ints off Bytestring

2007-12-24 Thread Paulo J. Matos
On Dec 23, 2007 12:44 PM, Isaac Dupree [EMAIL PROTECTED] wrote:

 -- this should work too
 parseHeader3 :: BS.ByteString - Maybe (Int, Int)
 --note accurate type signature, which helps us use Maybe failure-monad,
 --although losing your separate error messages

Oh gee, I just noticed that my type sig is in fact not correct. How
come GHC doesn't complain?

 parseHeader3 bs = do
(x, rest) - BS.readInt $ BS.dropWhile (not . isDigit) bs
(y, _) - BS.readInt $ BS.dropWhile (not . isDigit) rest
return (x, y)

What happens then if the first BS.readInt return Nothing???

 --or to be clearer without syntactic sugar, that is
 parseHeader3 bs =
(BS.readInt $ BS.dropWhile (not . isDigit) bs)
  = \(x, rest) -
 (BS.readInt $ BS.dropWhile (not . isDigit) rest)
= \(y, _) -
   return (x, y)

 Isaac



 Paulo J. Matos wrote:
  On Dec 23, 2007 12:32 PM, Paulo J. Matos [EMAIL PROTECTED] wrote:
  Hello all,
 
  It is either too difficult to get two integers of a bytestring, in
  which case something should be done to ease the process or I should
  learn much more Haskell. I guess the latter is the correct guess.
 
  I have a bytestring containing two naturals. I was to get them as
  efficiently as possible. Here's my code:
 
  Just tried a better one, what do you think of this:
  parseHeader2 :: BS.ByteString - (Int, Int)
  parseHeader2 bs =
  case (BS.readInt $ BS.dropWhile (not . isDigit) bs) of
Nothing - error Couldn't find first natural.
Just (x, rest) -
case (BS.readInt $ BS.dropWhile (not . isDigit) rest) of
  Nothing - error Couldn't find second natural.
  Just (y, _) - (x, y)
 
  parseHeader :: BS.ByteString - (Int, Int)
  parseHeader bs =
  let first = BS.readInt $ BS.dropWhile (not . isDigit) bs
  in
if(isNothing first)
then
error Couldn't find first natural.
else
let second = BS.readInt $ BS.dropWhile (not . isDigit) $
  snd $ fromJust first
in
  if(isNothing second)
  then
  error Couldn't find second natural.
  else
  (fst $ fromJust first, fst $ fromJust second)
 
  This seems to work:
  parseHeader $ BS.pack hello 252 359
  (252,359)
 
  Is there a better way?
 
  Cheers,
 
  --
  Paulo Jorge Matos - pocm at soton.ac.uk
  http://www.personal.soton.ac.uk/pocm
  PhD Student @ ECS
  University of Southampton, UK
 
 
 
 







-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Comments on reading two ints off Bytestring

2007-12-24 Thread Paulo J. Matos
On Dec 24, 2007 11:55 AM, Paulo J. Matos [EMAIL PROTECTED] wrote:
 On Dec 23, 2007 12:44 PM, Isaac Dupree [EMAIL PROTECTED] wrote:
 
  -- this should work too
  parseHeader3 :: BS.ByteString - Maybe (Int, Int)
  --note accurate type signature, which helps us use Maybe failure-monad,
  --although losing your separate error messages

 Oh gee, I just noticed that my type sig is in fact not correct. How
 come GHC doesn't complain?

  parseHeader3 bs = do
 (x, rest) - BS.readInt $ BS.dropWhile (not . isDigit) bs
 (y, _) - BS.readInt $ BS.dropWhile (not . isDigit) rest
 return (x, y)

 What happens then if the first BS.readInt return Nothing???


Ok, got it, I'm not returning a maybe. That's it then.
Still, the first question remains... what happens to (x, rest) if
BS.readInt returns Nothing.

-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Comments on reading two ints off Bytestring

2007-12-23 Thread Paulo J. Matos
Hello all,

It is either too difficult to get two integers of a bytestring, in
which case something should be done to ease the process or I should
learn much more Haskell. I guess the latter is the correct guess.

I have a bytestring containing two naturals. I was to get them as
efficiently as possible. Here's my code:
parseHeader :: BS.ByteString - (Int, Int)
parseHeader bs =
let first = BS.readInt $ BS.dropWhile (not . isDigit) bs
in
  if(isNothing first)
  then
  error Couldn't find first natural.
  else
  let second = BS.readInt $ BS.dropWhile (not . isDigit) $
snd $ fromJust first
  in
if(isNothing second)
then
error Couldn't find second natural.
else
(fst $ fromJust first, fst $ fromJust second)

This seems to work:
 parseHeader $ BS.pack hello 252 359
(252,359)

Is there a better way?

Cheers,

-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Comments on reading two ints off Bytestring

2007-12-23 Thread Paulo J. Matos
On Dec 23, 2007 12:32 PM, Paulo J. Matos [EMAIL PROTECTED] wrote:
 Hello all,

 It is either too difficult to get two integers of a bytestring, in
 which case something should be done to ease the process or I should
 learn much more Haskell. I guess the latter is the correct guess.

 I have a bytestring containing two naturals. I was to get them as
 efficiently as possible. Here's my code:

Just tried a better one, what do you think of this:
parseHeader2 :: BS.ByteString - (Int, Int)
parseHeader2 bs =
case (BS.readInt $ BS.dropWhile (not . isDigit) bs) of
  Nothing - error Couldn't find first natural.
  Just (x, rest) -
  case (BS.readInt $ BS.dropWhile (not . isDigit) rest) of
Nothing - error Couldn't find second natural.
Just (y, _) - (x, y)

 parseHeader :: BS.ByteString - (Int, Int)
 parseHeader bs =
 let first = BS.readInt $ BS.dropWhile (not . isDigit) bs
 in
   if(isNothing first)
   then
   error Couldn't find first natural.
   else
   let second = BS.readInt $ BS.dropWhile (not . isDigit) $
 snd $ fromJust first
   in
 if(isNothing second)
 then
 error Couldn't find second natural.
 else
 (fst $ fromJust first, fst $ fromJust second)

 This seems to work:
  parseHeader $ BS.pack hello 252 359
 (252,359)

 Is there a better way?

 Cheers,

 --
 Paulo Jorge Matos - pocm at soton.ac.uk
 http://www.personal.soton.ac.uk/pocm
 PhD Student @ ECS
 University of Southampton, UK




-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Quickcheck generator for arrays of integers

2007-12-11 Thread Paulo J. Matos
Hello all,

I using an IArray to represent a matrix. I'm trying to write some
properties checks with Quickcheck.
Quickcheck lacks instance generators for arrays of ints for example,
is there anything I can use out there or should I define it myself?
(I'm asking because it seems to be something that other people already did)


Cheers,

-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] I'm translating All about Monads to Chinese

2007-12-10 Thread Paulo J. Matos
On Dec 3, 2007 12:39 PM, Albert Lee [EMAIL PROTECTED] wrote:
 I have been confussed by monad for a long time. and I can't stand for
 it any more. so I start to translate the tutorial All About Monads
 to my mother language Chinese.
 My English is not good enough, so this work is only for my own study~
 I know there are some other Chinese fellow in this list, wish it would
 be helpful.
 I will work for one chapter everyday.


Let me just add that it was (after reading several other tutorials)
All About Monads that enlightened me about them. :)

 the address is: http://www.kamang.net
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe






-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Why is this strict in its arguments?

2007-12-05 Thread Paulo J. Matos
I'm glad that my initial post generated such an interesting discussion
but I'm still not understanding why the first version of findAllPath
seems to be computing the whole list even when I just request the
head, while the second one doesn't. I thought that this was
denominated by findAllPath is strict in its arguments but it seems
that I haven't used the right terminology to explain what I really
wanted to understand.

-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why is this strict in its arguments?

2007-12-05 Thread Paulo J. Matos
On Dec 5, 2007 1:51 PM, Luke Palmer [EMAIL PROTECTED] wrote:

 On Dec 4, 2007 9:41 PM, Paulo J. Matos [EMAIL PROTECTED] wrote:
  Hello all,
 
  As you might have possibly read in some previous blog posts:
  http://users.ecs.soton.ac.uk/pocm06r/fpsig/?p=10
  http://users.ecs.soton.ac.uk/pocm06r/fpsig/?p=11
 
  we (the FPSIG group) defined:
  data BTree a = Leaf a
 | Branch (BTree a) a (BTree a)
 
  and a function that returns a list of all the paths (which are lists
  of node values) where each path element makes the predicate true.
  findAllPath :: (a - Bool) - (BTree a) - Maybe [[a]]
  findAllPath pred (Leaf l) | pred l = Just [[l]]
| otherwise = Nothing
  findAllPath pred (Branch lf r rt) | pred r = let lfpaths = findAllPath pred 
  lf
   rtpaths = findAllPath pred 
  rt
   in
 if isNothing lfpaths 
  isNothing rtpaths
 then Nothing
 else
 if isNothing lfpaths
 then Just (map (r:)
  $ fromJust rtpaths)
 else
 if isNothing rtpaths
 then Just (map
  (r:) $ fromJust lfpaths)
 else Just (map
  (r:) $ fromJust rtpaths ++ fromJust lfpaths)
| otherwise = Nothing

 I don't think this evaluates the whole tree every time, but it
 certainly evaluates more than it needs to.  It has to do with an extra
 check.  Here's a very operational description:

 First note that if findAllPath returns Nothing, then it has evaluated
 the tree down to the contour where all the preds are false.  Let's
 suppose that this is the best possible case, where there is a path
 down the left side of the tree with no backtracking where all nodes
 are true.

 findAllPath pred (Leaf l) = Just [[l]]

 Now:

 if isNothing lfpaths  ...   -- false already, lfpaths is a Just, go
 to else branch
 else if isNothing lfpaths ... -- false again, go to else branch
 else if isNothing rtpaths ...

 To check this, you have to evaluate rtpaths down to its false contour
 before you can proceed.  You didn't need to do this.  Instead, writing
 the last else as:

 else Just (map (r:) $ fromJust lfpaths ++ fromMaybe [] rtpaths)

 Will get you behavior -- I think -- equivalent to the original.
 Except for that it will return paths in leftmost order rather than
 rightmost.  But changing the order of some of those checks will get
 you back the original rightmost behavior and lazy semantics.  Left as
 an exercise for the OP :-)


Oh, ok! :)

I think I got it now!
Thank you!

Cheers,

Paulo Matos

 Luke

  Later on we noticed that this could be simply written as:
  findAllPath :: (a - Bool) - (BTree a) - [[a]]
findAllPath pred = g where
g (Leaf l) | pred l = [[l]]
g (Branch lf r rt) | pred r = map (r:) $ (findAllPath pred
  lf) ++ (findAllPath pred rt)
g _  = []
 
  without even using maybe. However, 2 questions remained:
  1 - why is the first version strict in its arguments?
  2 - if it really is strict in its arguments, is there any automated
  way to know when a function is strict in its arguments?
 
  Cheers,
 
  --
  Paulo Jorge Matos - pocm at soton.ac.uk
  http://www.personal.soton.ac.uk/pocm
  PhD Student @ ECS
  University of Southampton, UK

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






-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Why is this strict in its arguments?

2007-12-05 Thread Paulo J. Matos
On Dec 5, 2007 1:43 PM, Benja Fallenstein [EMAIL PROTECTED] wrote:
 Hi Paolo,

 On Dec 5, 2007 2:09 PM, Paulo J. Matos [EMAIL PROTECTED] wrote:
  I'm glad that my initial post generated such an interesting discussion
  but I'm still not understanding why the first version of findAllPath
  seems to be computing the whole list even when I just request the
  head, while the second one doesn't.

 Because the function starts its work with

 if isNothing lfpaths  isNothing rtpaths
 then Nothing
 else ...

 which forces the evaluation of 'lfpaths' and 'rtpaths' to see whether
 they are Just or Nothing, which recursively forces the evaluation of
 findAllPath for the whole tree.


Oh, but lfpaths is not nothing so that means that isNothing rtpaths
shouldn't be evaluated, right?

 Hope this helps,
 - Benja






-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why is this strict in its arguments?

2007-12-05 Thread Paulo J. Matos
On Dec 4, 2007 10:00 PM, Neil Mitchell [EMAIL PROTECTED] wrote:
 Hi

  findAllPath :: (a - Bool) - (BTree a) - [[a]]
findAllPath pred = g where
g (Leaf l) | pred l = [[l]]
g (Branch lf r rt) | pred r = map (r:) $ (findAllPath pred
  lf) ++ (findAllPath pred rt)
g _  = []
 
  without even using maybe. However, 2 questions remained:
  1 - why is the first version strict in its arguments?

 Because in all call paths findAllPath will call g with its second
 argument. g will always evaluate (by pattern matching on) its value
 argument.


Wait! You're analyzing my second function and you're saying that it is
strict in its arguments?
Gee, that's bad. I questioned about the first one. The second seems to
be definitely lazy because I can use it on such big trees like I
showed. How come I can do this computation if like you said the
function is strict?

  2 - if it really is strict in its arguments, is there any automated
  way to know when a function is strict in its arguments?

 Yes, strictness analysis is a very well studied subject -
 http://haskell.org/haskellwiki/Research_papers/Compilation#Strictness
 . Essentially, an argument is strict if passing _|_ for that value
 results in _|_. So to take your example, evaluating:

 findAllPath a _|_
 g _|_
 _|_

 Since g tests what value _|_ has, we get bottom.

 Thanks

 Neil






-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Why is this strict in its arguments?

2007-12-05 Thread Paulo J. Matos
On Dec 5, 2007 10:44 AM, Jules Bean [EMAIL PROTECTED] wrote:
 Paulo J. Matos wrote:
  Hello all,

 Hi.


  findAllPath :: (a - Bool) - (BTree a) - Maybe [[a]]
  findAllPath pred (Leaf l) | pred l = Just [[l]]
| otherwise = Nothing
  findAllPath pred (Branch lf r rt) | pred r = let lfpaths = findAllPath pred 
  lf
   rtpaths = findAllPath pred 
  rt
   in
 if isNothing lfpaths 
  isNothing rtpaths
 then Nothing
 else
 if isNothing lfpaths
 then Just (map (r:)
  $ fromJust rtpaths)
 else
 if isNothing rtpaths
 then Just (map
  (r:) $ fromJust lfpaths)
 else Just (map
  (r:) $ fromJust rtpaths ++ fromJust lfpaths)
| otherwise = Nothing

 Ignoring the fact that you found a better way to write this entirely, a
 style point.

 Use of isNothing and fromJust and a cascade of ifs is generally a poor
 sign, much better to use case:

 findAllPath pred (Branch lf r rt)
  | pred r =
  case (findAllPath pred lf,findAllPath pred rt) of
(Nothing,Nothing)   - Nothing
(Nothing,Just rtpaths)  - Just (map (r:) rtpaths)
(Just lfpaths,Nothing)  - Just (map (r:) lfpaths)
(Just lfpaths,Just rtpaths) - Just (map (r:) $ rtpaths ++
 lfpaths)
  | otherwise = Nothing

 the general pattern is : replace isNothing with a case match on Nothing,
 replace fromJust with a case match on Just, don't be afraid to case two
 expressions at once.

 Hope someone finds that useful,


Thanks, Although I think that the general thread diverged from my
initial question, here it is again, why is this terrible function (I
know it is ugly) evaluating all of the resulting list when I just
request the head? (at seems from my experiments that's what it seems
to be doing).

BTW, I thought that the problem of  evaluating all of the resulting
list when I just request the head  was related to argument strictness
but from the other mails, I think I was wrong. :)

 Jules






-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Why is this strict in its arguments?

2007-12-05 Thread Paulo J. Matos
On Dec 5, 2007 12:16 AM, Aaron Denney [EMAIL PROTECTED] wrote:
 On 2007-12-04, Paulo J. Matos [EMAIL PROTECTED] wrote:
  Hello all,
 
  As you might have possibly read in some previous blog posts:
  http://users.ecs.soton.ac.uk/pocm06r/fpsig/?p=10
  http://users.ecs.soton.ac.uk/pocm06r/fpsig/?p=11
 
  we (the FPSIG group) defined:
  data BTree a = Leaf a
 | Branch (BTree a) a (BTree a)

 Totally avoiding your question, but I'm curious as to why you
 deliberately exclude empty trees.

 Come to think of it, how can you represent a tree with two elements?


Good question. I think we were just trying to define a tree in the
meeting and everyone agreed on this representation.

 Wouldn't

  data BTree a = Empty
   | Branch (BTree a) a (BTree a)

 be better?


Possibly :) I think that at the time nobody really cared about empty
trees! But for a really application we would have had to define them
probably. Now thinking about it, it seems like defining lists without
Null, strange, isn't it?

 --
 Aaron Denney
 --


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






-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Why is this strict in its arguments?

2007-12-04 Thread Paulo J. Matos
Hello all,

As you might have possibly read in some previous blog posts:
http://users.ecs.soton.ac.uk/pocm06r/fpsig/?p=10
http://users.ecs.soton.ac.uk/pocm06r/fpsig/?p=11

we (the FPSIG group) defined:
data BTree a = Leaf a
   | Branch (BTree a) a (BTree a)

and a function that returns a list of all the paths (which are lists
of node values) where each path element makes the predicate true.
findAllPath :: (a - Bool) - (BTree a) - Maybe [[a]]
findAllPath pred (Leaf l) | pred l = Just [[l]]
  | otherwise = Nothing
findAllPath pred (Branch lf r rt) | pred r = let lfpaths = findAllPath pred lf
 rtpaths = findAllPath pred rt
 in
   if isNothing lfpaths 
isNothing rtpaths
   then Nothing
   else
   if isNothing lfpaths
   then Just (map (r:)
$ fromJust rtpaths)
   else
   if isNothing rtpaths
   then Just (map
(r:) $ fromJust lfpaths)
   else Just (map
(r:) $ fromJust rtpaths ++ fromJust lfpaths)
  | otherwise = Nothing

Later on we noticed that this could be simply written as:
findAllPath :: (a - Bool) - (BTree a) - [[a]]
  findAllPath pred = g where
  g (Leaf l) | pred l = [[l]]
  g (Branch lf r rt) | pred r = map (r:) $ (findAllPath pred
lf) ++ (findAllPath pred rt)
  g _  = []

without even using maybe. However, 2 questions remained:
1 - why is the first version strict in its arguments?
2 - if it really is strict in its arguments, is there any automated
way to know when a function is strict in its arguments?

Cheers,

-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell code in Wordpress

2007-11-25 Thread Paulo J. Matos
Thanks all for your suggestions.

On Nov 23, 2007 10:31 PM, Duncan Coutts [EMAIL PROTECTED] wrote:
 On Fri, 2007-11-23 at 20:22 +, Paulo J. Matos wrote:
  Hi all,
 
  I'm curious about the best way to typeset haskell code in a wordpress
  blog. Using blockquote removes all indentation. :-(

 For the Gtk2Hs website I used a program (partly derived from hscolour)
 to highlight and adds links to documentation. It generates xhtml which
 one can just paste in.

 See the hello world example on this page:

 http://haskell.org/gtk2hs/documentation/

 The program is here:

 http://darcs.haskell.org/gtk2hs/docs/tools/AddLinks.hs


 Duncan






-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell code in Wordpress

2007-11-23 Thread Paulo J. Matos
Hi all,

I'm curious about the best way to typeset haskell code in a wordpress
blog. Using blockquote removes all indentation. :-(

Cheers,

-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Why can't Haskell be faster?

2007-11-01 Thread Paulo J. Matos
On 01/11/2007, Simon Peyton-Jones [EMAIL PROTECTED] wrote:
 Yes, that's right.  We'll be doing a lot more work on the code generator in 
 the rest of this year and 2008.  Here we includes Norman Ramsey and John 
 Dias, as well as past interns Michael Adams and Ben Lippmeier, so we have 
 real muscle!


That's very good to know. I wonder where could I read more about
current state of the art on Haskell compilation techniques and about
the implementation of ghc in general?
Is there a book on it or maybe some group of papers that would aid me
to understand it?

Cheers,

Paulo Matos

 Simon

 |  I don't think the register allocater is being rewritten so much as it is
 |  being written:
 |
 | From talking to Ben, who rewrote the register allocator over the
 | summer, he said that the new graph based register allocator is pretty
 | good. The thing that is holding it back is the CPS conversion bit,
 | which was also being rewritten over the summer, but didn't get
 | finished. I think these are both things which are likely to be done
 | for 6.10.
 |
 | Thanks
 |
 | Neil
 | ___
 | 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





-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Why can't Haskell be faster?

2007-10-31 Thread Paulo J. Matos
Hello all,

I, along with some friends, have been looking to Haskell lately. I'm
very happy with Haskell as a language, however, a friend sent me the
link:
http://shootout.alioth.debian.org/gp4/

which enables you compare several language implementations. Haskell
seems to lag behind of Clean.
From what I've seen of Clean it seems almost like Haskell. It even
distributes a Haskell-Clean translator so the obvious question is,
why is Haskell slower?
Being similar languages and being GHC a very good compiler, can't it
get at least as fast as Clean?

What am I missing here? (I wrote this mail assuming the results from
the URL are trustworthy).

Cheers,

-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Why can't Haskell be faster?

2007-10-31 Thread Paulo J. Matos
On 31/10/2007, Peter Hercek [EMAIL PROTECTED] wrote:
 Add to that better unbox / box annotations, this may make even
   bigger difference than the strictness stuff because it allows
   you to avoid a lot of indirect references do data.

 Anyway, if Haskell would do some kind of whole program analyzes
   and transformations it probably can mitigate all the problems
   to a certain degree.


So, I might assert that it is not a problem of the Haskell language
itself, it is a problem with the compiler. Which means that with
enough effort it would be possible for the compiler to generate
compiled code with performance as good as Clean.

 So the slowness of Haskell (compared to Clean) is consequence of
   its type system. OK, I'll stop, I did not write Clean nor Haskell
   optimizers or stuff like that :-D


type system? Why is that? Shouldn't type system in fact speed up the
generated code, since it will know all types at compile time?

 Peter.

 Peter Hercek wrote:
  I'm curious what experts think too.
 
  So far I just guess it is because of clean type system getting
   better hints for optimizations:
 
  * it is easy to mark stuff strict (even in function signatures
   etc), so it is possible to save on unnecessary CAF creations
 
  * uniqueness types allow to do in-place modifications (instead
   of creating a copy of an object on heap and modifying the copy),
   so you save GC time and also improve cache hit performance
 
  Peter.

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





-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Fast Paced Haskell Tutorial

2007-10-11 Thread Paulo J. Matos
Hello all,

I'm interested in a freely available fast paced haskell tutorial.
By fast paced, I means I want something that goes through basic in a
very fast pace, presents a couple of examples and then talks about
more advanced features. A set of tutorials would be also good.
References to these kind of tutorials would be great.

Cheers,
-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Using haskell with emacs

2007-08-08 Thread Paulo J. Matos
Thank you all for your references and tips, I'll be using them. :-)

On 06/08/2007, Jules Bean [EMAIL PROTECTED] wrote:
 Thomas Schilling wrote:
 
  On 6 aug 2007, at 22.11, Paulo J. Matos wrote:
  If you're used to Slime+Paredit, then there isn't something really
  comparable, but you get some basic interactive programming with the
  standard key-bindings:


 (But paredit does work in haskell-mode, and I find it useful...)

 Jules





-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Using haskell with emacs

2007-08-06 Thread Paulo J. Matos
Hi all,

I'm starting to learn haskell by my own, being currently mostly a
Common Lisp, Scheme, C++ programmer... I've got the haskell emacs mode
but can't find a manual. Moreover, I've found some keybindings on the
net but nothing that allows me to start an interpreter in emacs and
send definitions, one by one to the interpreter. Is this possible? Is
there any good reference of the emacs keybindings for haskell mode?

Cheers,

-- 
Paulo Jorge Matos - pocm at soton.ac.uk
http://www.personal.soton.ac.uk/pocm
PhD Student @ ECS
University of Southampton, UK
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe