Re[2]: [Haskell-cafe] Re: [Haskell] Google Summer of Code 2009

2009-02-11 Thread C.M.Brown
Hi Jamie,

As a side note - I'd be very interested to see a Haskell implementation of
H264 decoding. I'm currently having to use the ffmpeg library in C, and
it's notoriously buggy with memory leaks left right and centre. A
haskell solution would be very much welcome!

Regards,
Chris.


On Wed, 11 Feb 2009, Jamie wrote:

 Hi Bulat,

 On Wed, 11 Feb 2009, Bulat Ziganshin wrote:

  Hello Jamie,
 
  Wednesday, February 11, 2009, 5:54:09 AM, you wrote:
 
  Seems like it is ok to write H.264 in Haskell and released via GPL
  license?
 
  anyway it's impossible due to slow code generated by ghc

 I see, I guess I'll have to stuck with C version of H.264 in my Haskell
 programs.  Maybe in future when ghc have better optimizations.

 At least one can write various subset of H.323 standard in Haskell as the
 only part of H.323 subset that is CPU intensive is video/audio codecs, the
 rest is just mainly network I/O code.  http://www.h323plus.org/standards/

  Best regards,
  Bulatmailto:bulat.zigans...@gmail.com

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

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


Re: [Haskell-cafe] Haskell and Java interaction

2009-02-09 Thread C.M.Brown
Hi Silviu,

There's the GCJNI:
http://www.haskell.org/gcjni/

Which is basically a greencard-ed JNI interface for Haskell. I'm not sure
it's still suported but may be worth a shot.

Regards,
Chris.


On Mon, 9 Feb 2009, Silviu ANDRICA wrote:

 Hello,
   I was wondering if there is a way to call Haskell code from Java. I
 tried using jvm-bridge(http://sourceforge.net/projects/jvm-bridge/), but
 I'm stuck on building it.

 Thank you very much,
   Silviu
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

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


Re: [Haskell-cafe] Haskell and Java

2008-09-09 Thread C.M.Brown
Hi,

The only thing I can think of is GCJNI:

http://www.haskell.org/gcjni/

This makes use of the FFI and a Greencarded Java JNI interface. It does
allow you to call Java programs from Haskell. However, I'm not sure if it
is still supported.

hth,
Chris.


On Tue, 9 Sep 2008, [ISO-8859-1] Maurí­cio wrote:

 Hi,

 I use Haskell, and my friends at
 work use Java. Do you think it
 could be a good idea to use Haskell
 with Java, so I could understand
 and cooperate with them? Is there a
 a Haskell to Java compiler that's
 already ready to use?

 Thanks,
 Maurício

 ___
 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] Re: Haskell stacktrace

2008-09-09 Thread C.M.Brown
Or define your own ghead and gtail:

ghead msg [] = error ghead  ++ msg ++ []
ghead _ (x:xs)  = x


gtail msg [] = error gtail ++ msg ++ []
gtail msg (x:xs) = xs

and you can call them with a name of a function to give you an idea where
the error is occurring:

myHead = ghead myHead []

Chris.


On Tue, 9 Sep 2008, Ketil Malde wrote:

 Justin Bailey [EMAIL PROTECTED] writes:

  are using tail (or could be calling something that uses tail) and use
  the trace function to output logging info.

 Another cheap trick is to use CPP with something like:

 #define head (\xs - case xs of { (x:_) - x ; _ - error(head failed at 
 line++__FILE__++show __LINE__)})

 -k

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


Re: [Haskell-cafe] Haskell symbol ~

2008-08-27 Thread C.M.Brown
Hi,

I may be wrong here, but I don't belive it's just let-patterns that have
this property. I.e. what's the difference between...

(Just x) = _|_

f = x

vs.

f = let (Just x) = _|_ in x

vs.

f = x where (Just x) = _|_

I believe Haskell uses Normal Order Reduction in all these cases. Why is
it just let-patterns? Can you give an example?

Thanks,
Chris.




On Wed, 27 Aug 2008, Brandon S. Allbery KF8NH wrote:

 On 2008 Aug 27, at 14:23, Maurí cio wrote:
  What does '~' mean in Haskell? I
  read in haskell.org/haskellwiki/Keywords
  that “(...) Matching the pattern ~pat
  against a value always suceeds, and
  matching will only diverge when one of
  the variables bound in the pattern is
  used.” Isn't that true for any
  variable, due to lazyness?

 Only in let-patterns; others, including case expressions and top level
 definitions, are strict (which is in fact the normal way to force a
 value).


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


Re: [Haskell-cafe] Haskell symbol ~

2008-08-27 Thread C.M.Brown
I personally think it's bad to start using let-patterns as a synonym for
general pattern bindings when explaining these concepts. It may be
true that it's all transformed into the same thing at core level, but a let
expression binds a definition at the expression level, rather than at the 
equation level;
it becomes difficult when we have guards, for example:

f pat1
  | pat1 == x = x
  | pat2 == e2 = x
 where Just x = ...
f pat2 = ...

g pat1
  | pat1 == let Just x = ... in x = let Just x = ... in x
  | pat2 == e2 = let Just x = ... in x
g pat2 = ...

In theory x is lazy in f, but computed twice in g. The only way to make
the two the same is to introduce a case expression within a let binding
-- but then you have to start thinking about things like uncurrying g
if it has multiple parameters and its implications with partial applications.
Most decent compiler implementations would make a closue for x anyway (if
it's a big enough expression to compute), but I think it's certainly worth
making the distinction, otherwise new people are going to start thinking
they need to define everything using let clauses rather than wheres
for laziness.

Regards,
Chris.



On Wed, 27 Aug 2008, Jonathan Cast wrote:

 On Wed, 2008-08-27 at 20:14 +0100, C.M.Brown wrote:
  Hi,
 
  I may be wrong here, but I don't belive it's just let-patterns that have
  this property. I.e. what's the difference between...
 
  (Just x) = _|_
 
  f = x
 
  vs.
 
  f = let (Just x) = _|_ in x
 
  vs.
 
  f = x where (Just x) = _|_
 
  I believe Haskell uses Normal Order Reduction in all these cases. Why is
  it just let-patterns? Can you give an example?

 Those are all syntax sugar for let patterns.

 jcc



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


Re: [Haskell-cafe] Haskell Propeganda

2008-08-24 Thread C.M.Brown
Hi Brandon,

OK, so you're basically saying that segfaults can be eliminated with a
strong type system, whereas pattern matching errors is the result of some
dodgy laziness going on? I personally think such pattern matching errors
are a weaknesss of the language; with possibly no solutions to resolve.

regards,
Chris.



On Sat, 23 Aug 2008, Brandon S. Allbery KF8NH wrote:

 On 2008 Aug 23, at 17:29, C.M.Brown wrote:
  I wonder whether seg faults are the true analogue to errors such as
  error: head empty list. or pattern match errors.

 Not really; while laziness does introduce a certain amount of spooky
 action at a difference to such errors, it's not nearly as bad as the
 memory corruption (due to effective type mismatches) that often leads
 to the segfault.


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


Re: [Haskell-cafe] Haskell Propeganda

2008-08-23 Thread C.M.Brown
 I guess I didn't express my point very clearly... That C programmers
 apparently don't realise that a type system that's sound will give
 them something -- i.e. their programmer won't ever segfault.  I wonder
 when we try to advertise Haskell if we should be saying we can give
 you programs that never segfault, instead of we have a strong type
 system.

I'm sure this point is already made somewhere. But I certainly agree that
it's a useful point to make to C programmers who are interested in
Haskell.

I wonder whether seg faults are the true analogue to errors such as
error: head empty list. or pattern match errors.

Not that I'm saying we should be encouraging such errors in our Haskell 
programs.

Chris.

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


Re: empty case, empty definitions

2008-08-16 Thread C.M.Brown
Hi,


 Sounds bad. Consider:

 gray :: Color
 grey = newColor #ccc

 This fairly common style of bug now becomes perfectly valid Haskell,
 and if you always refer to grey, you may never even have a clue that
 the bug is present.

I think the compiler should certainly give a warning that no equations are
defined for a definition. It would be impossible to check for user typos!
:)

It does make me beg the question though: why do we want to define
data types without any constructors?

If we do opt for empty data declarations, then both general
pattern matching and case expressions need to be able to cope with it for
consistency.



Regards,
Chris

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


Re: [Haskell-cafe] Cyclic Inclusions

2008-08-13 Thread C.M.Brown
Andrew,

[...]

 For the record, I have no problem with modules depending on each other,
 so long as they only depend on their well-defined interfaces.

  Finally, as chris suggests, if separate compilation is important to
  you, why not have a flag in ghc -frequire-hi-boot or something?


 Well, if I wanted separate header files, and the inevitable multiple-
 maintenance headaches associated with them, I'd program in C.  Except
 for mutually recursive modules, GHC can and does generate header files
 automatically, so I don't see why my time should be wasted doing the
 job of a compiler.

 If something is preventing the compiler from doing that job, then that
 something should be fixed.

But isn't this exactly the point I was trying to make!? The whole point,
to me, in functional programming, is that we shouldn't have to worry about
the underlying implementation. What you've listed above are the restrictions
of a particular compiler implementation. All of which, if needed, can be
controlled by a flag if compilation performance is so important.

Regards,
Chris.

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


Re: [Haskell-cafe] Cyclic Inclusions

2008-08-13 Thread C.M.Brown
Andrew,

  But isn't this exactly the point I was trying to make!? The whole point,
  to me, in functional programming, is that we shouldn't have to worry about
  the underlying implementation.

 It is not exposing an underlying implementation detail to mandate that
 modules should have well-defined interfaces.  If anything, it's
 enforcing good programming practice.

I agree absolutely that having well-defined interfaces is a good
thing. I wasn't actually referring to that, I apologise for not being
clear.

However I saw no real argument for not having cyclic inclusions. You
say we shouldn't have to spend time writing hi-boot files, and yet you also 
think
that GHC should not do it automatically. So we have to restrict all
programmers to never writing cyclic inclusions?  :)


Kind Regards,
Chris.

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


Re: [Haskell-cafe] Cyclic Inclusions

2008-08-12 Thread C.M.Brown
Andrew,

Thanks very much for your reponse. It was very helpful; this makes a lot
of sense!

Regards,
Chris.

On Mon, 11 Aug 2008 [EMAIL PROTECTED] wrote:

 G'day all.

 Quoting C.M.Brown [EMAIL PROTECTED]:

  Yes, I saw that, thanks! I guess this is because it's hard to compile a
  mutually recursive module...

 It's because you don't need to declare the types of exported definitions.

 Consider, this highly artificial example:

  module A where

  import B

  f (x,y) = g (x,'A')


  module B where

  import A

  g (x,y) = f (True,y)

 To infer the types of f and g, you need to analyse both modules together.

 And yes, some people think that this is a bug in the specification.

 Cheers,
 Andrew Bromage
 ___
 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] Cyclic Inclusions

2008-08-12 Thread C.M.Brown
 I'm not sure that it does make a lot of sense -- we allow (mutually)
 recursive functions, even though they come with an efficiency
 penalty.  Why should we not allow (mutually) recursive modules, even
 though they too come with an efficiency penalty.  This is even an
 example where the efficiency loss is *only* at compile time, and only
 happens once, so it's somewhat a better situation than allowing
 mutually recursive functions.

 I'd say it falls very heavily into the ghc-bug category, not the spec
 bug category (even if there's reasons for the bug existing in ghc).

Perhaps it would be better for GHC to allow compilation of cyclic
inclusions via a flag? -fcyclic or something?
Or, to do it by default unless a -fno-cyclic flag is raised?
It does seem strange that the only way to compile cyclic modules is
to hack together a build using hi-boot files.

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


Re: [Haskell-cafe] Cyclic Inclusions

2008-08-12 Thread C.M.Brown
 The problem is not mutually recursive modules.  Plenty of statically
 typed languages support mutually recursive modules.

 The problem is that it's impossible in general to say what the
 interface of a module is by examining the module alone.  This is a
 very unusual property as real-world programming languages go.

 You could fix this by, for example, requiring that all symbols
 exported from a module have an explicit type annotation.  Or, if you
 think that's not lazy enough, it could be an error to use an imported
 symbol that doesn't have an explicit type annotation.  You could even
 formalise .hi-boot files if you were truly desperate.

I don't really see this as being any kind of real issue at all. Surely all
GHC needs to do is to concatenate all the modules together, alpha-reduce
the import/export relations and do a compile/type check over the
concatenated module.



 If the Haskell spec requires that multiple modules be analysed
 simultaneously (or multiple times to fixpoint), then that's a bug in
 the spec.  Separate compilation is too important.

Why is it a bug in the spec exactly? And why is separate compilation so
important?

Chris.


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


[Haskell-cafe] Cyclic Inclusions

2008-08-11 Thread C.M.Brown
Hi,

I have a question about cyclic inclusions. It appears in the Haskell 98
report that mutually recursive modules are allowed, however GHC complains
at any Haskell project that has cyclic inclusions (implicit or explicit).
Am I right in thinking that this is a GHC limitation?


http://www.haskell.org/onlinereport/modules.html


Kind regards,
Chris.



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


Re: [Haskell-cafe] Cyclic Inclusions

2008-08-11 Thread C.M.Brown
Hi Don,


 GHC provides a mechanism to support mutually recursive modules, but
 you  must break the cycle manually, via a boot file.

 
 http://www.haskell.org/ghc/docs/latest/html/users_guide/separate-compilation.html#mutual-recursion



Yes, I saw that, thanks! I guess this is because it's hard to compile a
mutually recursive module...


Chris.

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


Re: [Haskell-cafe] Trouble with non-exhaustive patterns

2008-07-21 Thread C.M.Brown
Hi Fernando,

I hope you don't mind, but I've moved this over to the Haskell-beginners
mailing list, where I think this kind of question will be more
appropriate.

In Haskell, it helps to think of functions in terms of an input and an
output, that is, what is the thing that is going into the function; and
what is the thing that is coming out of the function?

In your function, final, the input is clearly a list of something (we can
denote this by the Haskell type [a] which means a list of some type,
a). Its return type is clearly an element of the list, so that must be the
something type (the 'a' from the [a]). This gives the Haskell
type:

final :: [a] - a

(final takes a list of 'a' and gives back a single 'a'. The 'a' is a
type variable, and it is used to denote that anything can be put in its
place, so we can give final a list of integers, characters, whatever).

Now, let's take a look at your definition of final. If we take a closer
look, in fact only two equations satisfy this type:

final [a] = a
final (_:t) = final t

The other takes a list and returns a list. The equation,

final [] = []

takes an empty list and returns an empty list (its type is therefore
[a] - [a]).

This is why you got an error, as Haskell doesn't know how what
to do with the conflicting equation. What we need is the final element of
the list. How do we do that?

Let's think of the simple cases first. The final element of a list
containing a single element is just that element,

final [a] = a

But what about if the list contains more elements? Or is an empty list?
The empty list may be confusing, as an empty list contains no elements, so
in effect, we can't return anything. We can, however, return an error
message.

fun [] = error empty List

And the final element of any list, must be the final element of its tail:

final (_:t) = final t

this gives us:

final :: [a] - a
final [] = error Empty List
final [a] = a
final (_:t) = final t

I hope that gives some insight.

Kind regards,
Chris.



On Mon, 21 Jul 2008, Fernando Rodriguez wrote:


 Hi,

 I defiend the  following function to get the last element of a list:

 final [a] = a
 final (_:t) = final t

 and it works as expected. Since I didn't want to have a non exhaustive 
 pattern,
 I added the following case:

 final []  = [] - I consider that the end of an empty list is the empty list
 final [a] = a
 final (_:t) = final t

 Suddenly, the function stoped working with a rather cryptic (for a newbie
 at least) error message:

 *Temp final [4,5]

 interactive:1:9:
 No instance for (Num [a])
   arising from the literal `5' at interactive:1:9
 Possible fix: add an instance declaration for (Num [a])
 In the expr*Temp ession: 5
 In the first argument of `final', namely `[4, 5]'
 In the expression: final [4, 5]

 What have I done so wrong?

 Thanks in advance,
 Fernando



 ___
 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] Re: Call Graph Tool?

2008-06-27 Thread C.M.Brown
Hi Ivan,

 Assuming I get it included, is there any features in particular you'd want to
 see in there?  Note that if I do have it produce visualisations, they'll be
 static images as part of an analysis report rather than being interactive.

I'd basically like to see a graph of the overall struture of a Haskell
project: what modules import what, and so forth. This would be useful to
show which modules are forming the core of a system say, and which modules
are acting on the top layer.

Hope that gives some insight...
Chris.

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


Re: [Haskell-cafe] Call Graph Tool?

2008-06-27 Thread C.M.Brown
Hi Jno,

 I suggest that you have a look at HaSlicer, a (visual) Haskell
 slicing tool available online from http://labdotnet.di.uminho.pt/
 HaSlicer/HaSlicer.aspx , developed by Nuno Rodrigues ([EMAIL PROTECTED]).

Oh excellent, yes I'd forgotten about this, thanks.

Chris.

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


[Haskell-cafe] Call Graph Tool?

2008-06-26 Thread C.M.Brown
Hi,

I have approx. 100+ source files and I was wondering if anyone has a tool
that would let me see a visual call graph for the source files; i.e. a
visual hierarchy of which module is imported by what, and so forth.

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


Re: how do I abstract this pattern ?

2008-05-21 Thread C.M.Brown
On Wed, 21 May 2008, HP Wei wrote:


 Suppose p1, p2, p3 are 3 predicates
 that take an input -- say, a String.
 They return either (True, result)
 or False.

 I want to get an effect like in this expression:

 case p1 s of
(True, r) - r
False - case p2 s of
(True, r) - r
False - case p3 s of
(True, r) - r
False - none

 Is this a job for Maybe monad ?
 How do I do that ?


I think this is a job for the Either monad:

data Either a b = Left a | Right b

case p1 s of
(Left (True, r)) - r
(Right False) - case p2 s of
(Left (True, r)) - r
(Right False) - case p3 s of
(Left (True, r)) - r
(Right False) - none

So you wrap up your (Bool, result) type using Left, and your Bool type
using Right.

Regards,
Chris.




 Thanks
 HP
 ___
 Glasgow-haskell-users mailing list
 Glasgow-haskell-users@haskell.org
 http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: how do I abstract this pattern ?

2008-05-21 Thread C.M.Brown
On further thought, better to use the Maybe afterall. You can use Nothing
to signify your False and Just to signify your result.

case p1 s of
  Just result - result
  Nothing - case p2 s of ...

That's probably more intuitive to what you were intending.
Chris.


On Wed, 21 May 2008, C.M.Brown wrote:

 On Wed, 21 May 2008, HP Wei wrote:

 
  Suppose p1, p2, p3 are 3 predicates
  that take an input -- say, a String.
  They return either (True, result)
  or False.
 
  I want to get an effect like in this expression:
 
  case p1 s of
 (True, r) - r
 False - case p2 s of
 (True, r) - r
 False - case p3 s of
 (True, r) - r
 False - none
 
  Is this a job for Maybe monad ?
  How do I do that ?
 

 I think this is a job for the Either monad:

 data Either a b = Left a | Right b

 case p1 s of
 (Left (True, r)) - r
 (Right False) - case p2 s of
 (Left (True, r)) - r
 (Right False) - case p3 s of
 (Left (True, r)) - r
 (Right False) - none

 So you wrap up your (Bool, result) type using Left, and your Bool type
 using Right.

 Regards,
 Chris.




  Thanks
  HP
  ___
  Glasgow-haskell-users mailing list
  Glasgow-haskell-users@haskell.org
  http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
 
 ___
 Glasgow-haskell-users mailing list
 Glasgow-haskell-users@haskell.org
 http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


runstmt within API

2008-04-23 Thread C.M.Brown
Hello,

I want to use the ghc evaluator on the fly for some refactorings within
HaRe. However, I notice that runstmt ::Session - String - IO RunResult.

Is there anyway I can grab the result of the evaluated expression as a
String (rather than it being outputted to the terminal)?

It seems RunResult is defined:

data RunResult
= RunOk [Name]-- names bound by the expression
| RunFailed
| RunException GHC.IOBase.Exception

If I can't grab its result, is there a way to query the [Name] to get a
list of bindings in String format? Preferably something like
it = expression.

Kind regards,
Chris.

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


RE: Error Interpreting Main with API

2008-04-22 Thread C.M.Brown
Hi Simon,

 Yes I do, please!  Would you feel up to doing so?  I'm sure Simon'd check 
 your text for veracity!

I have modified the wiki, and added a new section under initialisation:
http://www.haskell.org/haskellwiki/GHC/As_a_library

Would it also be appropriate to modify that wiki page to reflect some of
the changes between 6.6.1 and 6.8.2? I don't mind doing this at some point
today or tomorrow...

Regards,
Chris.

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: Error Interpreting Main with API

2008-04-21 Thread C.M.Brown
Simon,

 The GHC API is behaving just like --make: it links the program if you
 have a Main module.  To ask it not to link, you want to do the same as
 '--make -c', which in the GHC API means setting the ghcLink field of
 DynFlags to NoLink.

Thanks, this has solved the problem I was having. I wonder whether it
would be a good idea to amend the Wiki page to relect this? I think it is
reasonable to assume that other users are going to want to use the API
against Main modules and it's possibly not too clear at the moment how to
do this.

Regards,
Chris.

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Error Interpreting Main with API

2008-04-18 Thread C.M.Brown
Hello,

I am trying to use the API to interpret a Main module and get some type
information from it. However, everytime I try to load a Main.hs module
using the API I get the following error message:

/usr/local/packages/ghc-6.8.2/lib/ghc-6.8.2/libHSrts.a(Main.o): In
function `real_main':
Main.c:(.text+0x7): undefined reference to `__stginit_ZCMain'
Main.c:(.text+0x36): undefined reference to `ZCMain_main_closure'
collect2: ld returned 1 exit status

If I create an empty file called Main within the directory where
Main.hs is located the program suceeds, I'm guessing this is because
there is no linking involved. Is there an extra flag I need to pass to GHC
in order to avoid this error? It works perfectly if I try it on a
module that is not called Main.

main =
  defaultErrorHandler defaultDynFlags $
  do
   let packageConf = /usr/local/packages/ghc-6.8.2/lib/ghc-6.8.2
   session - GHC.newSession {-JustTypecheck-} (Just (filter (/= '\n')
packageConf))
   dflags0 - getSessionDynFlags session
   (f1,b) - parseDynamicFlags dflags0 [-fglasgow-exts]
   setSessionDynFlags session f1{verbosity=6, hscTarget = HscInterpreted}
   target - GHC.guessTarget
/home/cmb21//HaRe_Project/testing/subIntroPattern/Main.hs Nothing
hscTarget=HscNothing}
   GHC.addTarget session target
   GHC.load session GHC.LoadAllTargets
   usermod - findModule session (mkModuleName Main) Nothing
   setContext session [usermod] []
   return session

I hope somebody can share some light!
Kind regards,
Chris.
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: [Haskell-cafe] Re: ANN: haskell-src-exts 0.3.2

2008-03-18 Thread C.M.Brown
Hi Nikolas,

 I supppose you're talking about HaRe, that Thomas Schilling linked to.
 I have no idea how that system is built so I can't answer your
 question. But in principle I don't see why not. :-)

In principle it would actually be quite difficult. HaRe is Haskell 98,
built upon the Programatica front end, and to use extensions would mean a
port to a system that has extensions (ghc say) and a re-evaluation of all
the current refactorings so that they work over extensions as well.

Porting to a system like GHC would require an almost complete re-engineering of 
HaRe, and,
although simple in theory, in practice it has so far presented some
problems. With the exposure of the GHC API though, we hope to address this
issue in the near future.


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


Re: [Haskell-cafe] Re: ANN: haskell-src-exts 0.3.2

2008-03-18 Thread C.M.Brown
 I believe that the limitation is that they use Programatica's parser
 to get an AST to run their refactorings on.  I think they've looked
 several times at using ghc's apis to do this, but hit various
 problems.  I think that the main problem is that no other parser
 preserves things like code layout and commenting, which is of course
 pretty critical to refactoring programs in a sane kind of way.

I think the main issue was that we looked at the port too early. I believe
GHC would offer everything in terms of position information
but at the time of the port there were issues such as
Strafunski traversing over GHC's AST (now made possible with derivable
instances); together with time restraints and the learning curve of GHC's
internals.

There is a technical report available that details some of the work:
(Porting HaRe to the GHC API)

http://www.cs.kent.ac.uk/pubs/2005/2266/

Thanks,
Chris.



 Thanks

 Tom
 ___
 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


GHC Internals Changed

2008-01-14 Thread C.M.Brown
Hi,

It seems that GHC's API interface has changed between 6.6 and 6.8. Most
notably, JustTypecheck and GHC.dropForAlls are no longer in scope.

Are the changes documented anywhere? The notes on the hackage commentary
still seem to point to the previous API internals.

http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/API

Kind regards,
Chris.
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: network package

2008-01-13 Thread C.M.Brown
Thanks for everyone's help with this so far. However, I'm having some
problems using cabal:

Whenever I try to

runghc Setup.hs install

a cabal file (I've tried parsec and network) I get an error message
similar to this:

Setup.hs: parsec.cabal:15: Unknown field 'build-type'

I tried to install Cabal from darcs and I also got an error message when
trying to configure:

Setup.lhs: cabal-install.cabal:30: Invalid syntax (no colon after field
name)

Does anyone else have these problems? Or, am I doing something obviously
wrong?

Thanks,
Chris.



On Fri, 11 Jan 2008, Don Stewart wrote:

 cmb21:
  Hi,
 
  I have just built and installed ghc-6.8.2 on my linux box but I can't find
  the network package. Has it been moved or left out?

 It's not installed by default. You can find it on hackage.haskell.org,

 http://hackage.haskell.org/cgi-bin/hackage-scripts/package/network-2.1.0.0

 As the Haskell community is moving to a more distributed development
 model (with a central archive).

 You can also build and install 'cabal-install', to make installation
 easy.

 $ cabal install network

 Cheers,
   Don

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: network package

2008-01-13 Thread C.M.Brown

 Looks like your version of cabal is a bit old. Try updating to the 1.2.3
 or 1.3 series. You can find it on hackage.haskell.org

I'm using the runghc command from ghc-6.8.2, is that right?

[EMAIL PROTECTED] ~/filepath-1.0 $ which runghc
/usr/local/packages/ghc-6.8.2/bin/runghc


Cheers,
Chris

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: network package

2008-01-13 Thread C.M.Brown
 runghc finds ghc in the path, so it might be using a ghc from /usr/bin
 or somesuch. Try compiling Setup with ghc 6.8.2 instead
 (ghc --make Setup).

Excellent, that worked a treat! thanks.

Chris.



 Thanks
 Ian


___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


network package

2008-01-11 Thread C.M.Brown
Hi,

I have just built and installed ghc-6.8.2 on my linux box but I can't find
the network package. Has it been moved or left out?

Kind regards,
Chris.
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: [Haskell-cafe] Refactoring status

2008-01-03 Thread C.M.Brown
Hi Peter,

 Is any work being done on Haskell refactoring support, like HaRe or others?

HaRe is still very active and is due for a new release very soon.
There are probably in excess of 40 refactorings for HaRe in total now, and
I intend to add more! Sadly, I am currently the only maintainer left
on the project, so I am busy trying to implement new refactorings and
finish off my thesis.

 Is anyone actively using refactoring? When using C#, I used Resharper a lot,
 and ever since, I'm really hooked to refactoring, so I miss it a lot when
 doing Haskelling. (I never seem to get a function name or signature right
 the first time. is it just me? J)

The greatest problem that the HaRe group have experienced is that HaRe
supports Haskell 98. While this is the perfect model for academic
investigation and Haskell tool design, most of the real world use the de
facto standard of GHC haskell. We would really like HaRe to be ported over to 
GHC at some point
in the near future.

 I'm currently using Emacs with Haskell Mode (which does not offer
 refactoring support) but I think many of you use VIM (which does support
 it?)
 Can one use refactoring outside of an editor? This does not really sound
 practical,  but maybe it works?

HaRe works with both Emacs and VIM; you can also use it from a command
prompt meaning that it can be integrated into any tool that you require.
Indeed, there was even some investigation of porting it to Sub Etha Edit
with great success!

 PS: IMHO I don't think text should be the source format of our files. I
 think we should use a standarized decorated AST as the source, from which we
 can derive a textual (but also graphical) view and editor. Any comments on
 that? J

You mean a syntax-directed editor, right?

Kind regards,
Chris.

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


RE: [Haskell-cafe] Refactoring status

2008-01-03 Thread C.M.Brown
 Cool! I'll check it out. However, I'm using some GHC extensions, so that
is
 indeed a show stopper :)

Which extensions are you using that are not Haskell 98? I would be very
interested to know what users would generally require from a refactorer.

  You mean a syntax-directed editor, right?

 Yes, but also that a compiler should directly read the syntax tree; the
 frontend part of the compiler should really be the editor, providing
 round-trip editing between text - AST. Nothing new really, I used to
work
 with a 6502 assembler on the Commodore 64 that did exactly that :)

I agree with Neil, AST editors are generally ugly and hard to use. There
is also the problem of laying out Haskell code. Everyone uses their own
layout style and pretty printing ASTs is generally a bad thing to do in
this context.

Cheers,
Chris.

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


Re: [Haskell-cafe] Refactoring status

2008-01-03 Thread C.M.Brown
Hi Bulat,

 i don't use
 type signatures at all - this creates some problems when i wrote large
 portion of code and try to make it compile, but nothing more

I believe type signatures are the very essence of Haskell documentation!
I'd much rather see a program with type signatures for functions and
little (or no) comments over programs with no type signatures and
ambigious comments (if any comments at all!).

Type signatures really does make dealing with someone elses code that
much easier.

Regards,
Chris.


 
 
 
  Hi all,
 
   
 
  Is any work being done on Haskell refactoring support, like HaRe or others?
 
   
 
  Is anyone actively using refactoring? When using C#, I used
  Resharper a lot, and ever since, I▓m really hooked to refactoring,
  so I miss it a lot when doing Haskelling. (I never seem to get a
  function name or signature right the first time┘ is it just me? J)
 
   
 
  I▓m currently using Emacs with Haskell Mode (which does not offer
  refactoring support) but I think many of you use VIM (which does support 
  it?)
 
   
 
  Can one use refactoring outside of an editor? This does not really
  sound practical,  but maybe it works?
 
   
 
  Thank you,
 
  Peter
 
   
 
  PS: IMHO I don▓t think text should be the source format of our
  files┘ I think we should use a standarized decorated AST as the
  source, from which we can derive a textual (but also graphical) view
  and editor┘ Any comments on that? J
 
   
 
   
 
   
 
   
 

 
 
 
   
 
 
 



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


RE: [Haskell-cafe] Refactoring status

2008-01-03 Thread C.M.Brown
 Currently, I'm trying to learn arrows and Yampa (mainly to see how well it
 compares to my own dataflow/reactive stuff that was written in C#, C++ and
 assembler)

Arrows won't work with HaRe at the moment, therefore Yampa won't either;
which is a shame.

 First of all, let's see if I get the concept of a syntax directed editor
 right. The idea is, that I (or my company), has a specific indentation rule,
 naming convention rule, etc... When I get code from someone else (in a
 syntax tree form ala XML), it will immediately show the text using my
 conventions.

Yep, this was what I was thinking to some extent.

Furthermore, when I need to perform refactoring, a rename is
 just *one* change to the entire system, no matter how many other files use
 the name; no more merging for stupid renames.

I'm a little confused as to what you mean here. A renaming renames all
(and only those) uses of an identifier within a particular definition, and
not every use of a particular name. The binding structure of the program
must not be affected; and there must be no introduction of ambiguity in
the namespace. You can do this with HaRe, but HaRe currently refactors
Programatica data types. If you can
somehow convert your AST into what HaRe expects then the refactoring will
work, but you will need to tweak our pretty printer (and turn off layout
preservation).

When diffing, whitespace,
 indentation, etc does not matter; the structure of the files is compared
 instead.

There is also (preliminary at the moment) duplicate code detection built
into HaRe. This is based on the principle of looking at the shape of functions 
and
expressions, concentrating on where variables are bound and whether one
term is an intance of another. Duplicate expressions can be converted into
a more general abstraction, transforming the duplicate expressions into
function calls (parameterised by their differences).

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


RE: [Haskell-cafe] Refactoring status

2008-01-03 Thread C.M.Brown
 Furthermore, IMHO, type signatures alone are not enough, a good parameter
 name says at least as much as the type.

Yes! A very good point! :)


 E.g. what does a function Int - Int - Bool do? I have no idea. A good
 function name helps, e.g. isDivisible:: Int - Int - Bool. But then I still
 don't know which parameter is the numerator and denominator. So good names
 for the parameters are at least as important, e.g. isDivisible ::
 numerator:Int - denonimator:Int - Bool


I agree. But I was generally thinking of more complex functions than this,
especially if they use some kind of user-defined monad and have implicit
parameters, say.

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


Re: [Haskell-cafe] Refactoring status

2008-01-03 Thread C.M.Brown
Hi,

 A possible first goal would be, to add extensions that are definitely in
 Haskell prime, see:

 http://hackage.haskell.org/trac/haskell-prime/wiki/Status'#definitely-inProposalStatus

Oh great! Thanks for the link, I think the main issue is moving over to a
platform that is heavily maintained (such as GHC) and then working
towards, say, haskell prime coverage as a first goal.

 It would be nice to have it built in to the functional programming
 extensions of Eclipse
 ( http://eclipsefp.sourceforge.net/ )

Yes, I actually did some work on this but due to time restrictions it was
never finished. However, it wouldn't be difficult to add HaRe to any type
of interactive environment. HaRe is called from the command prompt and
requires positional and region information from the editor together with
the facility to display a prompt and read answers.

I would love to be able to work with people who may be interested in
porting HaRe to editors such as Eclipse... :)

Cheers,
Chris.

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


Re[2]: [Haskell-cafe] Refactoring status

2008-01-03 Thread C.M.Brown
On Fri, 4 Jan 2008, Bulat Ziganshin wrote:

 Hello Peter,

 Thursday, January 3, 2008, 11:03:58 PM, you wrote:

  Okay, but when using a syntax directed editor, type signatures can be
  automatically provided because the types are known.

 the same is possible for Haskell - it's possible to add to code type
 signatures deduced by the compiler

Ha! Yes, HaRe also has the facility to do this have I plugged it
enough yet? :-)

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


Re: [Haskell-cafe] OOP'er with (hopefully) trivial questions.....

2007-12-18 Thread C.M.Brown
 If however, you *really* want to keep your shapes as being seperate
 types, then you'll want to invoke the class system (note, not the same
 as OO classes).

 class Shape a where
area :: a - Int

 newtype Circle = C Int

 instance Shape Circle where
area (C r) = pi * r^2

 newtype Rectangle = R Int Int

 instance Shape Rectangle where
area (R h w) = h * w

 newtype Square = Sq Int

 instance Shape Square where
area (Sq l) = l * l

 -- Now we can do something with our shapes
 doubleArea :: Shape a = a - Int
 doubleArea s = (area s) * 2

Perhaps introduce an existensial quantification?

data Shape = forall a. Sh a = Shape a

class Sh a where
  area :: a - Float

data Circle = Circle Float

instance Sh Circle
  area (Circle r) = pi*r*2

data Rect = Rect Float Float

instance Sh Rect
  area (Rect h w) = h * w

doubleArea :: Shape - Float
doubleArea (Shape x) = (area x) * 2

I think this is more in the traditional OOP sense. But this way or Tom's:
one would have to convert functions like equality over Values of type
Shape into equality over different types (Circle and Rect). This can be
done using case analysis over the types with something like read.

Kind regards,
Chris.

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


Re: GHC 6.8.1 on Mac OS X 10.5 (Leopard)

2007-11-17 Thread C.M.Brown
Ian,

 Is there a way for GHC on OS X to find where it was run from, so that it
 can find package.conf?

The command:

ghc --print-libdir

should do it.


Cheers,
Chris.

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: [Haskell-cafe] let vs. where

2007-11-14 Thread C.M.Brown
Hi David,

 A let clause would work fine here:

 someFunction ls a b c = let listLen = length ls
 someAuxFunction x y = ... listLen ...
 someOtherFunction x y = ... listLen ...
 in
 ... listLen ...

 it's just that you don't want to mix let and where clauses, because then
 things get confusing.  Even if it worked with both, noone would know the
 binding rules.

Possibly in that case, but there are cases where I believe they are not
the same.

For example:

gg n = ([1..,10^6*n], [1..10^6*n])

exp = (fst $ gg 1000, snd $ gg 1000)

this could be captured nicely in a where clause:

exp = (fst blah, snd blah) where blah = gg 1000

But a let would have to be placed in both elements of the tuple - and
therefore being evaluated twice (unless the implementation is smart enough
to work out they can be shared?):

exp = (let blah = g 1000 in fst blah, let blah = g 1000 in snd blah)

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


Re: [Haskell-cafe] let vs. where

2007-11-14 Thread C.M.Brown
Hi Neil,

 Why not:

 exp = let blah = g 1000
  in (fst blah, snd blah)

Yes, fair enough.

 Where's always get desugared to let's, so where's are never more efficient.

Interesting. I'm thinking a where-to-let refactoring and its converse may
make useful routine refactorings for HaRe.

Cheers,
Chris.

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


[Haskell-cafe] Strange Type Inference

2007-11-05 Thread C.M.Brown
Hi,

I was given a quandary this evening, suppose I have the following code:

module Test1 where

import qualified Data.Map as Map

testFunction :: Ord a = Map.Map a b - Map.Map a b - a - (Maybe b,
Maybe b)
testFunction m0 m1 k = (lookup0 k, lookup1 k)
where
  lookup0 x  = Map.lookup x m0

  lookup1 x  = Map.lookup x m1

This compiles and type checks fine. However, the only way I could add type
signatures to lookup0 and lookup1 was to do something along the lines
of this:

testFunction :: Ord a = Map.Map a b - Map.Map a b - a - (Maybe b,
Maybe b)
testFunction m0 m1 k = (lookup0 k m0, lookup1 k m1)
where
  lookup0 :: (Monad m, Ord a) = a - Map.Map a b
- m b
  lookup0 x m0 = Map.lookup x m0

  lookup1 :: (Monad m, Ord a) = a - Map.Map a b
- m b
  lookup1 x m1 = Map.lookup x m1

Is there a way to give lookup0 and lookup1 explicit type signatures
without passing in m0 and m1 as parameters? (So their definitions are the
same as in the first example) If ghc can infer the type, surely it must
be possible?


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


Re: [Haskell-cafe] Strange Type Inference

2007-11-05 Thread C.M.Brown
 Yes, using a ghc extension of scoped type variables.  In the signature
 of testFunction, if you explicitly quantify all your variables with
 forall, then they are visible in the where clause (and elsewhere in
 the function).

Perfect! But how come if I have:

testFunction :: forall a b. Ord a = Map.Map a b - Map.Map a b - a -
(Maybe b, Maybe b)

I get:

Test1.hs:6:34: parse error on input `='

Is the syntax incorrect?

Many thanks
Chris.

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


Re: [Haskell-cafe] Strange Type Inference

2007-11-05 Thread C.M.Brown

 I get:

 Test1.hs:6:34: parse error on input `='

 Is the syntax incorrect?

Scrap that, I forgot to enable the glasgow extensions. It's been a long
day. *sigh* :)

Chris.

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


Re: [Haskell-cafe] Why isn't pattern matching lazy by default?

2007-09-19 Thread C.M.Brown
Hi Peter,

 Mmm, yes of course... blush...

 But shouldn't

 f ~(x:xs) = rhs

 give a compile-time error since neither x nor xs is used in the right
 hand side, and hence nothing will ever get pattern matched when this
 function is called, which clearly indicates a mistake? That is, if I
 understand lazy pattern matching correctly... And then in these cases
 the user would have to annotate the pattern match as being strict, so he
 is aware of the eager evaluation taking place

Well if you defined f:

f ~(x:xs) = 1 + 2
f ~[] = 42

Then you will get a warning stating that the pattern matches of (x:xs)
and [] are overlapped. It may not be a mistake though, so possibly a bold
error for the compiler to throw, it just means that 1+2  will always be
evaulated no matter what list you throw at it (provided of course that
the result of f is needed to evaluate the rest of the program).

It's interesting to note that if you had:

f ~(x:xs) = x + 2
f ~[] = 42

Then f [] would give a complie error:
 Irrefutable pattern failed for pattern (x : xs)

Hope that gives some insight.
Chris.



 Oh well, the way it is now is also easy to get used to, one just has to
 know how it works (just like M-theory ;-) )

 Cheers,
 Peter


 Neil Mitchell wrote:
  Hi
 
 
   Now why isn't pattern matching lazy by default?  This seems odd for a
  newbie since everything else is lazy by default.
 
 
  f ~(x:xs) = rhs
  f ~[] = rhs'
 
  Now guess what f [] does...
 
  If you use a where binding then pattern matching is lazy.
 
  Thanks
 
  Neil
 
 
 


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


Re: [Haskell-cafe] Why isn't pattern matching lazy by default?

2007-09-19 Thread C.M.Brown

 f ~(x:xs) = x + 2
 f ~[] = 42

 Then f [] would give a complie error:
  Irrefutable pattern failed for pattern (x : xs)

Sorry, that should be *runtime* error!

Chris.




 Hope that gives some insight.
 Chris.


 
  Oh well, the way it is now is also easy to get used to, one just has to
  know how it works (just like M-theory ;-) )
 
  Cheers,
  Peter
 
 
  Neil Mitchell wrote:
   Hi
  
  
Now why isn't pattern matching lazy by default?  This seems odd for a
   newbie since everything else is lazy by default.
  
  
   f ~(x:xs) = rhs
   f ~[] = rhs'
  
   Now guess what f [] does...
  
   If you use a where binding then pattern matching is lazy.
  
   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


Re: [Haskell-cafe] Why isn't pattern matching lazy by default?

2007-09-19 Thread C.M.Brown
 It seems GHC does give a warning at compile-time about it, so you did
 get it right the first time :-)

Well the warning happens at compile time certainly. But the irrefutable
pattern error only occurs at runtime.


cmb21$ ghc --make Main.hs
[1 of 1] Compiling Main ( Main.hs, Main.o )

Main.hs:3:0:
Warning: Pattern match(es) are overlapped
 In the definition of `f': f ~[] = ...
Linking Main ...



cmb21$ ./a.out
a.out: Main.hs:(3,0)-(4,10): Irrefutable pattern failed for pattern (x :
xs)

Cheers,
Chris.


 Thanks for the info,
 Peter



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


Re: [Haskell-cafe] Why isn't pattern matching lazy by default?

2007-09-19 Thread C.M.Brown
Hi Miguel,

 See, in let or where constructs you don't have a choice; you can't do
 different things depending on whether some value is Just x or
 Nothing. Therefore, there is no need to perform pattern matching
 strictly.

This is not entirely true. This is actually one of those niches in Haskell
where the left to right is not quite the same as right to left. A let can be 
converted to a where
but the other way round may require a case introduction.

So just like you can define:

f (Just x) = x
f Nothing  = error Nothing

You can also define:

f x = g x
   where
 g (Just x) = x
 g Nothing = error Nothing

g is strict in its first argument. Declared in a let it would look like:

f x = let g x = case x of
   (Just y) - y
   Nothing - error Nothing  in g x

Again, g must be strict in its first argument.

Chris.


 ___
 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] Why isn't pattern matching lazy by default?

2007-09-19 Thread C.M.Brown
Hi Isaac


 or

 f x = let
   g (Just x) = x
   g Nothing = error Nothing
in g x


That's interesting, thanks!


Chris.

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


RE: [Haskell-cafe] Ideas

2007-08-25 Thread C.M.Brown
 I tried vital, and at first sight it is very nice, but they only support a
 very limited subset of Haskell, perform no type checking at all, don't
 support the indent rule, etc... Anyway it is an amazing piece of work.

I believe that type-sensitive manipulation was certainly being
investigated; however, I can't confirm as to how far it *was*
investigated.

What intriged me mostly was how it can display infinite data structures
lazily. I think it's certainly a great tool for teaching some aspects of
functional programming: helping newbies to understand and define data
structures, say.

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


RE: [Haskell-cafe] Ideas

2007-08-25 Thread C.M.Brown
 Definitely! It's really cool stuff. But something like that for real Haskell
 (e.g. GHC) would be even better :) I could be an offline downloadable
 application. It would be a very nice tool: create postscript (or PDF, or
 LaTex, whatever rich text format) documents with Haskell boxes inside.
 Real literate programming... Oh well ;)

I would personally say Haskell 98 is real Haskell (well, until Haskell
Prime comes out). It becomes difficult for tool developers to cater for
non-standard languages; Haskell is quite complicated enough without having to 
cater
for all the little nuances and idiomatic extensions that are constantly
added with each release of a compiler.

I believe it does work as an offline downloadable tool...

http://www.cs.kent.ac.uk/projects/vital/install/index.html

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


[Haskell] What makes a functional language functional?

2007-08-09 Thread C.M.Brown
Hi,

Is lazy evaluation necessary for a functional language to remain
functional?

The reason I ask is that because it violates beta-reduction, and also
referential transparency (I think). In haskell, we can transform:

g x + f x

into:

f x + g x

as both f and g do not change the parameter x.

If g always evaluates to a normal form (in both a lazy and a strict world)

g x = x

but f is defined thus:

f x = (\y - if x /= 0 then x else y/x)

And we apply f to 0 (1/0) then f becomes _|_

therefore:

0 + _|_ /= _|_ + 0

Or, does this just become:

_|_ = _|_ ?

Or, am I missing something totally obvious?

Regards,
Chris.


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


Re: [Haskell] What makes a functional language functional?

2007-08-09 Thread C.M.Brown
Hi Jeremy,

Thanks for this very informative answer! This has certainly helped to
clear up a number of points.

Thanks,
Chris.


 Many arguments have been had about what it means for a language to be
 functional, so that's probably not a productive line of discussion.
 (ICFP carefully doesn't stipulate language choice for the programming
 contest, for example.)

 Both eager and lazy evaluation can be pure, providing referential
 transparency: all that matters of an expression is its value, and a
 subexpression may be substituted with a different one having the same
 value without changing the meaning of the surrounding context. This
 fails on languages supporting side effects.

 Lazy evaluation is necessary, however, in order to treat a function
 definition as a (universally applicable) equation. In Haskell, I can
 define

   three x = 3

 and then infer, for any expression x, that the equation

three x = 3

 holds. With eager evaluation, that's no longer the case: if x denotes
 a non-terminating or error-raising computation, then

three x /= 3

 The equation then requires a side condition:

three x = 3,  for well-defined x

 which complicates equational reasoning, but it doesn't break
 referential transparency.

 Jeremy


 On 9 Aug 2007, at 10:30, C.M.Brown wrote:

  Hi,
 
  Is lazy evaluation necessary for a functional language to remain
  functional?
 
  The reason I ask is that because it violates beta-reduction, and also
  referential transparency (I think). In haskell, we can transform:
 
  g x + f x
 
  into:
 
  f x + g x
 
  as both f and g do not change the parameter x.
 
  If g always evaluates to a normal form (in both a lazy and a strict
  world)
 
  g x = x
 
  but f is defined thus:
 
  f x = (\y - if x /= 0 then x else y/x)
 
  And we apply f to 0 (1/0) then f becomes _|_
 
  therefore:
 
  0 + _|_ /= _|_ + 0
 
  Or, does this just become:
 
  _|_ = _|_ ?
 
  Or, am I missing something totally obvious?
 
  Regards,
  Chris.
 
 
  ___
  Haskell mailing list
  Haskell@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell



 [EMAIL PROTECTED]
Oxford University Computing Laboratory,TEL: +44 1865 283508
Wolfson Building, Parks Road,  FAX: +44 1865 283531
Oxford OX1 3QD, UK.
URL: http://www.comlab.ox.ac.uk/oucl/people/jeremy.gibbons.html



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


Re: [Haskell-cafe] Order of evaluation

2007-07-26 Thread C.M.Brown
Hi Jon,

On Thu, 26 Jul 2007, Jon Harrop wrote:


 If you have a boolean-or expression:

   a || b

 will a be evaluated before b in Haskell as it is in other languages?


Yes, I believe it is defined thus:

True || _= True
_|| True = True
_|| _= False

Therefore it is strict in its first argument (it needs to evaluate its
first argument in order to know which pattern match to take).

Chris.


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


Re: [Haskell-cafe] newbie question on Parsers from Programming In Haskell

2007-06-04 Thread C.M.Brown
Hi Juozas,

 -

 type Parser a = String - [(a, String)]

 return :: a - Parser a
 return v = \inp - [(v, inp)]

 failure :: Parser a
 failure = \inp - []


 item :: Parser Char
 item = \inp - case inp of
   [] - []
   (x:xs) - [(x, xs)]


 parse :: Parser a - String - [(a, String)]
 parse p inp = p inp


 (=) :: Parser a - (a - Parser b) - Parser b
 p = f = \inp - case parse p inp of
   [] - []
   [(v, out)] - parse (f v) out


 p :: Parser (Char, Char)
 p = do x - item
item
y - item
return (x, y)  -- LINE 34
 

I tried the above in both ghci and hugs. The problem that I found was that
firstly both interpreters were trying to load the default implementations
of return and =. The problem specifically lies within the do notation.
This is special syntactical sugar Haskell uses to allow the laying out of
monadic code more aesthetically pleasing. What is also happening is that
the particular Haskell implementations automatically use the default
implementations for return and = (defined within the Prelude library).

Try the following:

module Arb where

type Parser a = String - [(a, String)]

return2 :: a - Parser a
return2 v = \inp - [(v, inp)]

failure :: Parser a
failure = \inp - []


item :: Parser Char
item = \inp - case inp of
  [] - []
  (x:xs) - [(x, xs)]


parse :: Parser a - String - [(a, String)]
parse p inp = p inp


(=) :: Parser a - (a - Parser b) - Parser b
p = f = \inp - case parse p inp of
  [] - []
  [(v, out)] - parse (f v) out


p :: Parser (Char, Char)
p = item = (\x - (item = (\_ - item = (\y - return2 (x,y)


In the above p is written using lambda expressions.

f = p = (\x - return x) can be read the same as:

f = do
x - p
return x


I hope that gives some insight.

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


Re: 2-days old in Haskell

2007-06-01 Thread C.M.Brown
Hi Tope,

 When I tried to compile it as instucted on the webpage ( $ ghc  -o hello
 hello.hs), I got this error message.

are you actually typing in that '$' into the command prompt? try leaving
out the '$' and just type ghc -o hello hello.hs.

Chris.

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: FW: GHC as a library

2007-05-30 Thread C.M.Brown
Hi Kenny,


 \begin{code}

 main = do
 session - GHC.newSession GHC.JustTypecheck (Just Test.hs)

 dflags1 - GHC.getSessionDynFlags session
 (dflags2, packageIds) - Packages.initPackages dflags1
 GHC.setSessionDynFlags session dflags2{GHC.hscTarget=GHC.HscNothing}

 let name = Test.hs
 target - GHC.guessTarget name Nothing
 GHC.addTarget session target
 GHC.load session GHC.LoadAllTargets

 let preludeModule = GHC.mkModule (PackageConfig.stringToPackageId
 base) (GHC.mkModuleName Prelude)
 GHC.setContext session [] [preludeModule]

 m_checkedModule - GHC.checkModule session (GHC.mkModuleName Test)
 ...

 \end{code}

 I am hoping to retrieve the inferred types of the declared Ids in Test.hs
 At this stage, what  I obtain is a value of type Maybe CheckedModule.

You can certainly get the type of an arbritrary expression in your project
module using something like the following:


ghcTypeCheck session expr modName =
  unsafePerformIO(
   do

   Just ty - exprType session (modName ++ . ++ expr)

   ty' - cleanType ty
   return $ showSDoc $ ppr ty'
  )

cleanType ty = do
  return $! GHC.dropForAlls ty

That may be of some help...

Cheers,
Chris.

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Pretty printing type annotations

2007-05-03 Thread C.M.Brown
Hi,

I was wondering if there was an easy way to pretty print the result of the
type checker from GHC. I basically want the format that GHCi spits out,
rather than a type annotation with qualified types. I know I can knock up
a parser that removes the qualifiers, but I was wondering if there was a
simple function that I could call that would just printy print it for me
(and saving me the work).

The type checker gives me something of the form:

(GHC.Num.Num t1, GHC.Num.Num t) = t1 - t - t1

But GHCi gives me the same without any qualifying.

Hope someone can help.
Chris.
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: [Haskell] refactoring, catamorphism, termination of programs

2007-05-02 Thread C.M.Brown
Hi Jahannes,

 I don't want to make a big research project out of this,
 rather I think of quickly putting together a prototype
 that proves the concept.

 I figure it could be distilled from some existing refactoring suite,
 or be manufactured from existing building blocks.

Well, HaRe -- the Haskell refactorer -- offers a full API for building
transformations and refactorings for the full Haskell 98 standard.

http://www.cs.kent.ac.uk/projects/refactor-fp/hare.html

A new release will hopefully be released very soon (even in the next
few days) which will be compatible with ghc-6.6.1.
The releases on our refactoring page currently only work with GHC-6.4.*.

 E.g. Language.Haskell.* from the ghc libs,
 and perhaps Typing Haskell in Haskell?
 http://citeseer.ist.psu.edu/424440.html

HaRe also uses the GHC API and type checker, with parts of the HaRe API
extended to retrieve type information from GHC on abritrary expressions
and functions.

Kind regards,
Chris.
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


Re: ghc configure

2007-05-01 Thread C.M.Brown
Hi Simon,

 Mainly this is due to modularity: many of the library packages can be built
 entirely separately from GHC, so their configure scripts are designed to be
 standalone.


Yes, I guess it would be a fair bit of work to have it check that you are
building the whole of GHC as opposed to separate modules. I just thought
that it could check to see if it was a global build -- and share configure
checks where appropriate; or, in separate module builds the configure runs
as normally.

 I know that configure takes a long time on Windows, but I'm surprised if it's 
 a
 bottleneck for other platforms.  How long does the build take?  Have you taken
 steps to speed up the build as described in the Building Guide?

Configuring and building on my Mac can take several hours. Mind you, it's
a slow machine (G4 1.33 with 1 gig of RAM). I can safely say it's very
fast on my linux machine - the configure whips through, and even a full
build only takes a little more than an hour or so.

Thanks for pointing out tips to speed up the build. I must confess my
ignorance of not checking that!

Kind regards,
Chris.

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: [Haskell-cafe] Poor first impression

2007-04-27 Thread C.M.Brown
Hi Fernando,

 [EMAIL PROTECTED] ghc-6.6.1]# ghc
 /usr/local/lib/ghc-6.6.1/ghc-6.6.1: error while loading shared libraries:
 libreadline.so.4: cannot open shared object file: No such file or directory
 #

 So, I conclude that Haskell is not ready for prime time, if it cannot
 install itself correclty including shared libs in a standard Fedora Core 6
 system.

 Goodbye Haskell, I just wanted to compile a MP3 player, and perhaps if the
 compiler installed OK with no issues, I'd have taken a look at the language.
 But as of right now, I don't have time to waste with broken compiler
 installers.

Wow! Such a bitter response! All you need to do is install readline, found
here:

http://tiswww.case.edu/php/chet/readline/rltop.html

I think it's unfair to blame GHC for not having readline; the website does
indeed tell you about readline:

http://www.haskell.org/ghc/download_ghc_661.html

Check out the paragraph under Linux (x86).

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


ghc configure

2007-04-26 Thread C.M.Brown
Hi,

I've noticed that when you run ./configure on a ghc build lot's of
repetition occurs. A lot of the time the same checks are being performed for
each configure file in the ghc hierarchy. Could it be possible if some of
these checks could be done once at a high level and then subsequent
configures could refer to these checks to speed up
configuration time? It's just configuring ghc on a mac G4 is a very time
consuming process in it's own right!

Thanks,
Kind regards,
Chris.
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Buildng ghc-devel from macports

2007-04-12 Thread C.M.Brown
Hello,

I've been trying to build the ghc-devel package (6.7) from macports.
However the build seems to fail half through. Specifically when running
the setup for base-2.1:

configure: Using compiler: ../../compiler/ghc-inplace
configure: Compiler flavor: GHC
configure: Compiler version: 6.7.20070411
configure: Using package tool: ../../utils/ghc-pkg/ghc-pkg-inplace
configure: Using ar found on system at: /usr/bin/ar
configure: Using haddock found on system at: /opt/local/bin/haddock
configure: Using ld given by user at: /usr/bin/ld
configure: No pfesetup found
configure: Using ranlib found on system at: /usr/bin/ranlib
configure: Using runghc found on system at: /opt/local/bin/runghc
configure: No runhugs found
configure: Using tar found on system at: /usr/bin/tar
configure: Using happy: /opt/local/bin/happy
configure: Using alex: /opt/local/bin/alex
configure: Using hsc2hs: ../../utils/hsc2hs/hsc2hs-inplace
configure: No c2hs found
configure: No cpphs found
configure: No greencard found
Setup: Unrecognised flags:
 --with-cc=gcc
make[1]: *** [stamp/configure.library.build-profiling.base] Error 1
make: *** [stage1] Error 2

Hope someone can help!
kind regards,
Chris.
___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


[Haskell-cafe] Strange behaviour with writeFile

2007-02-04 Thread C.M.Brown
Hi,

I am observing some rather strange behaviour with writeFile.

Say I have the following code:

answer - AbstractIO.readFile filename
let (answer2, remainder) = parseAnswer answer
if remainder ==   answer2 == 
  then do
AbstractIO.putStrLn $ completed
  else do
AbstractIO.putStrLn answer2
AbstractIO.writeFile filename remainder

With the above I get an error saying the resources to filename are
locked. If I add the line AbstractIO.putStrLn $ show (answer2, remainder)
before I call writeFile it suddenly magically works!

Has anyone seen strange behaviour like this before?

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


Re: [Haskell-cafe] Strange behaviour with writeFile

2007-02-04 Thread C.M.Brown
Hi Neil,

 When you add that extra line the act of writing out the remainer
 causes the rest of the input to be fully evaluated and hence the
 filehandle is closed.

Ah, yes of course :)

I've found that:

let (answer2, remainder) = parseAnswer (force answer)

where

force  :: Eq a = a - a
force x = if x==x then x else x

Seems to do the trick.

Thanks!
Chris.

 On 04/02/07, C.M.Brown [EMAIL PROTECTED] wrote:
  Hi,
 
  I am observing some rather strange behaviour with writeFile.
 
  Say I have the following code:
 
  answer - AbstractIO.readFile filename
  let (answer2, remainder) = parseAnswer answer
  if remainder ==   answer2 == 
then do
  AbstractIO.putStrLn $ completed
else do
  AbstractIO.putStrLn answer2
  AbstractIO.writeFile filename remainder
 
  With the above I get an error saying the resources to filename are
  locked. If I add the line AbstractIO.putStrLn $ show (answer2, remainder)
  before I call writeFile it suddenly magically works!
 
  Has anyone seen strange behaviour like this before?
 
  Regards,
  Chris.
  ___
  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


ghc 6.6.1?

2007-01-12 Thread C.M.Brown
Hi,

I was wondering when ghc-6.6.1 will be released? I am asking because a
patch has been made to the ghc repo to allow multple calls to the
ghc.newSession within the API and HaRe depends on this.

Regards,
Chris.
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Compiling 6.6 repos on Mac OS X

2007-01-03 Thread C.M.Brown
Hi,

I have recently tried to compile the 6.6 version of ghc from the darcs
repository.

I followed the intructions to pull ghc from the repository:

darcs get --partial http://darcs.haskell.org/ghc-6.6/ghc
cd ghc
chmod +x darc-add
./darcs-add -extra pull

The build process seems to get past stage 1, but fails at the beginning of
stage 2:

../compiler/ghc-inplace -optc-O -optc-Wall -optc-W
-optc-Wstrict-prototypes -optc-Wmissing-prototypes
-optc-Wmissing-declarations -optc-Winline -optc-Waggregate-return
-optc-Wbad-function-cast -optc-I../includes -optc-I. -optc-Iparallel
-optc-DCOMPILING_RTS -optc-fomit-frame-pointer -optc-fno-strict-aliasing
-H16m -O -optc-O2 -static -I. -#include HCIncludes.h -fvia-C -dcmm-lint
-c Linker.c -o Linker.o
Linker.c: In function 'loadObj':

Linker.c:1383:0:
 error: 'misalignment' undeclared (first use in this function)

Linker.c:1383:0:
 error: (Each undeclared identifier is reported only once

Linker.c:1383:0:  error: for each function it appears in.)
make[1]: *** [Linker.o] Error 1
make: *** [stage1] Error 1

I am compiling this with ghc-6.6 (the latest version from darcs) and gcc
4.0.

Kind regards,
Chris.


___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: [Haskell-cafe] Composing functions with runST

2007-01-03 Thread C.M.Brown
Hi,

 It's true that this is the typical way of learning Haskell, but I for
 one think it's a bad way of learning Haskell.
 Very few real world programs get by without the impure stuff, so if
 you give the newbie the impression that it isn't there (by postponing
 it) there's a chance he'll run into a situation where he needs it
 before it's been even mentioned (queue newbie going bah, academic
 language and switching to C++).

I agree. It also confuses matters when the newbie is suddenly given a
library of IO code to use -- but told to ignore it -- they suddenly start
wondering why it is so difficult to do anything useful in Haskell. A
consequence of which seems that the student becomes afraid (and ignorant)
of Haskell.

 I find that the Haskell introductions I like the most are the ones
 that accompany papers about STM and such. I.e. ones which have to
 teach the reader about the basics of Haskell IO, but doesn't have
 enough space to start with the pretty stuff.

I agree with this also. I don't think it is a difficult feat teaching an
absolute beginner how do some some basic stuff with the IO monad. This
shows straight away that haskell can do some useful stuff other than
adding numbers together in Hugs.

Mix that with some actual
 comutations to show off some pretty stuff and you'll have a newbie who
 is both excited about the cool looking features of the pure aspects of
 Haskell, but completely aware of the fact that you can do impure stuff
 as well.

Yes, I wish this approach was applied much more often. Semi-related to
this: I taught an algorithms and data structures class last term. In one
of the classes the students were given an equation to solve and they were
frantically typing it into their calculators, replacing the variable
parameters with numbers. I told them they could all finish the class in 5 
minutes if they
used Haskell. Type the equation as it is and use higher-order functions to
work out the parameters. The look of horror on the student's faces when I
mentioned the 'H' word was priceless. However, they were all prepared to
spend 50 minutes writing a Java program which would have the same effect.

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


Re: [Haskell-cafe] Composing functions with runST

2007-01-03 Thread C.M.Brown
Hi,

 On the contrary, I think it's an excellent way of learning Haskell.
 I'm writing a lot of useful Haskell code with only one IO action
 (interact).  I don't think I could reasonably construct an
 introductory problem that couldn't be solved with it, and I haven't
 yet found an application for which I've needed more.  I think it's
 destructive to teach people we have a wonderful new paradigm of
 programming that solves all sorts of problems, but all we're going to
 use it for is doing what we did with C++ anyway.

Yes, but the point is most students have already been poisoned with C++
(or Java). They don't see the point in Haskell becuase they can't see the
wood for the trees.
The only way to get them interested in Haskell in the first place is to
make it look vaguely like C++ (or Java) -- it's like coercing a Donkey
with a carrot. Once they are interested - show them there is a lot more
to Haskell than imperative-style behaviour, that way they may also see
the elegence of purely functional programming.

 That's just my 2¢ -- I like Haskell specifically because I don't have
 to do things in order and I don't have to do things in an imperative
 style, I would love for more people to be taught about this wonderful
 thing.

So would I. But in reality it just doesn't seem to work like that.

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


Re: Using GHC API

2006-11-27 Thread C.M.Brown
Hi Ian,

After some playing around and hacking of my code, I finally got it to
work. The problem is that the hscTarget flag needs to be set to HscNothing
when running in the JustTypeCheck mode:

GHC.setSessionDynFlags ses $ dflags1 {verbosity = 1, hscTarget=HscNothing}

If you change the above line everything works. Something very subtle that
I compeletely overlooked.

Thanks for your help.
Chris.


On Sat, 25 Nov 2006, Ian Lynagh wrote:


 Hi Chris,

 On Fri, Nov 10, 2006 at 04:15:10PM +, C.M.Brown wrote:
 
  I am currently in the process of porting some of the Haskell
  Refactorer (HaRe) over to ghc 6.6. Part of HaRe requires the API and until
  now I've been content with using th 6.5 API. However, since I've started
  the switch I've noticed some strange problems and the latest is I am
  getting the following error when trying to find the type of an expression:
 
 
  interactive:1:0:
  Can't find interface-file declaration for Main.main
Probable cause: bug in .hi-boot file, or inconsistent .hi file
Use -ddump-if-trace to get an idea of which file caused the error

 Attached is a smaller module showing the same thing, along with the
 (trivial) Main.hs I was testing with.

 If I tell it to use Interactive mode then all is well:

 $ ./hasktags Interactive Main.hs
 Loading package base ... linking ... done.
 [1 of 1] Compiling Main ( Main.hs, Main.o )
 Just GHC.IOBase.IO ()

 but if I tell it to use JustTypecheck mode then it breaks:

 $ ./hasktags JustTypecheck Main.hs
 [1 of 1] Compiling Main ( Main.hs, Main.o )

 interactive:1:0:
 Can't find interface-file declaration for variable Main.main
   Probable cause: bug in .hi-boot file, or inconsistent .hi file
   Use -ddump-if-trace to get an idea of which file caused the error
 Nothing

 (remove *.hi *.o between runs)

 So it looks like using Interactive mode should allow you to get on for
 now.

 ghc --show-iface Main.hi gives

 interface main:Main 1 6070 where
 export main:Main main
 module dependencies:
 package dependencies: base
 orphans: base:GHC.Base
 family instance modules:
 main :: GHC.IOBase.IO ()
 main :: GHC.IOBase.IO ()

 in the first case, but the last two lines are missing in the second.

 This raises a few questions:

 Are there meant to be two main :: GHC.IOBase.IO () lines when it works?

 Should it work with JustTypecheck? It looks like the point of
 JustTypecheck is that IDEs should be able to ask the type of something
 actually written in the file, but would it actually be more expensive to
 allow the information to be used to type other expressions?

 Should JustTypecheck be generating a .hi and .o file at all? It seems
 wrong to me.

 Simons?


 Thanks
 Ian


___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: [Haskell] Re: [Haskell-cafe] SimonPJ and Tim Harris explain STM - video

2006-11-24 Thread C.M.Brown
Hi,

I got this working on Mac OS X. I had to download media player 9:

http://www.microsoft.com/windows/windowsmedia/software/Macintosh/osx/default.aspx

This contains the WMV3 codec.

Cheers,
Chris.


On Fri, 24 Nov 2006, James William Pye wrote:

 On Fri, Nov 24, 2006 at 10:26:38AM +0100, Tomasz Zielonka wrote:
  Does anybody know how to watch this on Linux? I would prefer to simply
  download the movie file and use MPlayer on that, but I failed.
 
  . or on Mac OS X (haven't tried yet)

 The latest mplayer works for me on FreeBSD/amd64 (1.0rc1, iirc).
 ___
 Haskell mailing list
 Haskell@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell

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


Using GHC API

2006-11-10 Thread C.M.Brown
Hi,

I am currently in the process of porting some of the Haskell
Refactorer (HaRe) over to ghc 6.6. Part of HaRe requires the API and until
now I've been content with using th 6.5 API. However, since I've started
the switch I've noticed some strange problems and the latest is I am
getting the following error when trying to find the type of an expression:


interactive:1:0:
Can't find interface-file declaration for Main.main
  Probable cause: bug in .hi-boot file, or inconsistent .hi file
  Use -ddump-if-trace to get an idea of which file caused the error


I have attached the code and would appreciate if someone could point me in
the right direction. Basically I just want to find the type of a
particular expression within a file. This used to work but now seems to
fail.

The code is compiled with:

ghc --make -package ghc-6.6 -o main hasktags.hs

and run with

./main Main.hs

The file main can have anything in it really - I'm just using it to find a
type of some function called main.

Thanks for you help!

Chris Brown.module Main where

import System
import Control.Exception
import System.IO.Unsafe
import System.IO
import List

-- Package GHC stuff
import GHC
import DynFlags
import ErrUtils
import PackageConfig
import HsSyn
import Outputable
import SrcLoc
import RdrName
import Name 


main :: IO ()
main = do
  args - getArgs
  realMain args

realMain :: [String] - IO ()
realMain [] =
  do
putErrStrLn Usage: ghctest files
realMain args =
  defaultErrorHandler defaultDynFlags $ do
ses - GHC.newSession JustTypecheck (Just 
/usr/local/packages/ghc-6.6/lib)
dflags0  - GHC.getSessionDynFlags ses
(dflags1,fileish_args) - GHC.parseDynamicFlags dflags0 []
GHC.setSessionDynFlags ses $ dflags1 {verbosity = 1}
targets - mapM (\a - GHC.guessTarget a Nothing ) args
mapM_ (GHC.addTarget ses) targets

dep - depanal ses [(mkModuleName Main)] True

res - GHC.load ses LoadAllTargets
case res of
  Failed -
do
  putErrStrLn Load failed.
  Succeeded - 
do
  putErrStrLn Load succeded.
  checked - GHC.checkModule ses (mkModuleName Main)
  case checked of
Nothing   - putErrStrLn Failed to check module.
Just _ -
  do
putErrStrLn Checked module.
-- Get the complete module graph
modGraph - getModuleGraph ses
taglist - sequence $ map
  (\modSum -
do
  Just cmod - GHC.checkModule ses (moduleName $ ms_mod 
modSum)
 
  let Just ps = typecheckedSource cmod
  putErrStrLn Renamed source: 
  putErrStrLn $ showSDoc $ ppr ps

  
  putErrStrLn Names: 
  ty - exprType ses Main.main
  putStrLn $ showSDoc $ ppr ty 

  ) modGraph
  
  
  

{- 
alltags - return $ concat taglist
sequence_ $ map (putStrLn . show) $ sort alltags
-}
putStrLn Done.


bindLN :: HsBind a - Maybe (Located a)
bindLN (FunBind ln _ _ _ _) = Just ln
bindLN _ = Nothing

debugLog :: String - b - b
debugLog msg b =
  unsafePerformIO (
do
  putErrStrLn msg
  return b
)

logAndDump :: (Outputable a) = String - a - b - b
logAndDump msg a b =
  unsafePerformIO (
do
  putErrStrLn msg
  putErrStrLn $ showSDoc (ppr a)
  return b
)

tidyFileName :: String - String
tidyFileName ('.':'/':str) = str
tidyFileName str   = str

data Tag = Tag TagName TagFile TagLine TagDesc
  deriving (Eq)

instance Ord Tag where
  compare (Tag t1 _ _ _) (Tag t2 _ _ _) = compare t1 t2

instance Show Tag where
  show (Tag t f l d) = makeTagsLine t f l d

type TagName = String
type TagFile = String
type TagLine = Int
type TagDesc = String

makeTagsLine :: String - String - Int - String - String
makeTagsLine tag file line desc = tag `sep` file `sep` (show line) `sep` 
;\t\ ++ desc ++ \
  where a `sep` b = a ++ '\t':b


putErrStrLn = hPutStrLn stderr
putErrStr = hPutStr stderr
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: GHC 6.6 for OS X using MacPorts

2006-10-27 Thread C.M.Brown
Hi Greg,

I have just been trying to install ghc 6.6 using Darwin Ports, but the
search facility can't find ghc-6.6. :

sudo port selfupdate
DarwinPorts base version 1.320 installed
Downloaded MacPorts base version 1.320
The MacPorts installation is not outdated and so was not updated
selfupdate done!

dhcp2940:~ cmb21$ port search ghc
ghclang/ghc   6.4.2The Glorious
Glasgow Haskell Compilation System
ghc-devel  lang/ghc-devel 6.5  The Glorious
Glasgow Haskell Compilation System (development version)

dhcp2940:~ cmb21$

Am I doing something wrong?

Kind regards,

Chris Brown,



On Fri, 27 Oct 2006, Gregory Wright wrote:


 Hi,

 GHC 6.6 is now available for OS X systems on both Intel and PowerPC
 processors using the MacPorts infrastructure.

 The compiler is built from source, using a binary bootstrap compiler.
 OS X
 versions 10.3 (Panther) and 10.4 (Tiger) are supported for PowerPC
 processors;
 for Intel processors, version 10.4.

 MacPorts (formerly Darwinports) is a packaging system for managing
 builds of unix-compatible software on OS X.  For more information on
 MacPorts,
 see

   http://www.macports.org/

 A new ghc-devel port will soon be available for those who just have
 to live on the bleeding edge.


 Best Wishes,
 Greg

 Gregory Wright
 Antiope Associates LLC
 [EMAIL PROTECTED]

 ___
 Glasgow-haskell-users mailing list
 Glasgow-haskell-users@haskell.org
 http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users