Re: [Haskell-cafe] Types

2009-11-26 Thread John Dorsey
 Hello,
 
 I´ve a small question about Haskell. It´s really vague explained in Haskell
 in 10 minutes and sometimes it's really detailed explained which is very
 hard for people who just got into Haskell to read. Can someone explain me
 something about the type Integral? What exactly is it?

Integral isn't actually a type; it's a type class.

Int is a fixed-size type; it's often 32 or 64 bits in practice, but you
can't rely on that portably.  Int operations are fast.

Integer is an unbounded-size type.  It's less efficient than Int, for
obvious reasons, but it's often more correct because it won't over or
underflow.

Integral is a class of types that support integer-like operations.  If you
ask ghci:

ePrelude :info Integral
class (Real a, Enum a) = Integral a where
  quot :: a - a - a
  rem :: a - a - a
  div :: a - a - a
  mod :: a - a - a
  quotRem :: a - a - (a, a)
  divMod :: a - a - (a, a)
  toInteger :: a - Integer
-- Defined in GHC.Real
instance Integral Integer -- Defined in GHC.Real
instance Integral Int -- Defined in GHC.Real

Any type for which those operations (quot, rem, div, and so forth) make
sense, can be made an instance of class Integral.  Int and Integer are two
types that are such instances.

 I know that 2 is something of the type Integral, however what does this
 differ from Int? The same question goes for Fractional and Floating, what
 exactly is their commonality and what exactly is their difference?

Numeric literals are a special case.  To make it possible to write 2 and
mean it as an Int or an Integer (or any other numeric type), 2 is defined
to *really* mean (fromIntegral 2).  fromIntegral is a function that takes an
Integral value (such as 2), and converts it to a type of your choice, so
long as it's a member of the Num class.

 Thank you for explaining these basic things to me.

This is one of those areas where Haskell beginners get quickly thrown a
handful of things that are unfamiliar (type classes, defaulting, tricky
numeric literals), while doing the most basic things (arithmetic).  Don't
despair; it'll make sense soon if it doesn't yet.

Regards,
John Dorsey

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


Re: [Haskell-cafe] Pattern Matching

2009-11-12 Thread John Dorsey
Casey,

 Why in a pattern match like
 
 score (1 3) = 7

You probably mean
 score 1 3 = 7

which applies the function 'score' to two arguments.  With the parentheses,
it looks like an application of '1' to the argument '3'.  But to answer your
actual question...

 can I not have
 
 sizeMax = 3
 
 score (1 sizeMax) = 7

When a variable name (such as 'sizeMax') appears in a pattern, it gets bound
there.  This is useful so you can refer to the variable on the right hand
side, as in:

successor x = x + 1

How would the compiler know whether to bind the variable (what actually
happens), or match against the value represented by some earlier binding
(what you're asking for)?

What if the type of that second argument doesn't have a defined equality
operation?

There might be some reasonable way to do it, but I suspect it would be
fragile and error-prone, at best.  So it's always a new binding.  It's easy
enough to work around:

score 1 x | x == sizeMax = 7

Regards,
John

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


Re: [Haskell-cafe] NetSnmp problem.

2009-10-22 Thread John Dorsey
   I am trying to use NetSnmp to get some information from my switch.
 And I met this problem.
   After initialize, I used snmpWalk to get some information, and
 dealed with it. Everything is fine. Then I sleep for 5 mins. SnmpWalk
 again. But this time, all asnValues were unsupported format, which
 broke my dealing process.

Are you on a 64-bit machine?  I've made an update or two, but haven't pushed
them to Hackage yet... I'll do that today.  Please let me know if this fixes
your problem.

John

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


Re: [Haskell-cafe] Need help with ghc static compile for cgi using mysql

2009-10-15 Thread John Dorsey
 lambdabot is currently hosted on the lowest end linode. The biggest hurdle I
[...]

+1.  I use linode for (most of) my Haskell work.

John

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


Re: [Haskell-cafe] I read somewhere that for 90% of a wide class of computing problems, you only need 10% of the source code in Haskell, that you would in an imperative language.

2009-10-01 Thread John Dorsey

Andrew Coppin said:
 Sure. But what is a computer program?

then Richard O'Keefe said:
 A computer program, in short, is *whatever we want it to be*.
 (Within reasonable limits.)

I agree with Richard's conclusion.

From where I sit, the critical point is that, unless you're breadboarding,
programming is working in the abstract, and we choose our abstractions.
There's a strong tradition of sequential imperative programming, but that's
as far as it goes.

John

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


Re: [Haskell-cafe] I read somewhere that for 90% of a wide class of computing problems, you only need 10% of the source code in Haskell, that you would in an imperative language.

2009-09-30 Thread John Dorsey
 Well, try this: Go ask a random person how you add up a list of numbers.  
 Most of them will say something about adding the first two together,  
 adding the third to that total, and so forth. In other words, the step  
 by step instructions.

You word the (hypothetical) question with a bias toward imperative
thinking.  You're asking How do you do this action?

Why isn't the question What is the sum of a list of numbers?, which is
biased toward the declarative?

John
(who's glad he's not a social scientist)

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


Re: [Haskell-cafe] Typeclasses vs simple functions?

2009-09-15 Thread John Dorsey
 perimeter :: Geometry - Double
 perimeter (Sphere _ r) = 0.0
 perimeter (Circle _ r) = 2.0 * pi * r
 
 The latter is even simpler because there is no need in extraction of Double
 value from Maybe.

I'd strongly advise against this last one on style grounds.  (0 :: Double)
isn't nearly as suitable as a distinguished value indicating an invalid
result as Nothing.  It can be made to work, in the same way that you can
write complex code in asm; instead, use a solution that gives you
type-level help in getting it right.  I'd use Maybe.

Regards,
John

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


Re: [Haskell-cafe] Where does documentation get installed with cabal?

2009-08-20 Thread John Dorsey
  I'm trying to find the API documentation for happstack 0.3
  (online is for 0.2).
[...]
 Max In most cases it is installed in
 Max ~/.cabal/share/doc/happstack*/html.  Is there any files at
 Max that directory?
 
 There are now, but only a very few. And very little contents in them.
 It's as if the --reinstall were partial.

Perhaps it's in /usr/local/share/doc.  Mine seem to end up there, and I
don't recall whether I specified that at any point.

It's not in my ~/.cabal/config, but I am using the very helpful
  user-install: False
  documentation: True

I suspect /usr/local/share/doc is the default for documentation in global
installs, but I can't go verify that at the moment.

Regards,
John

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


Re: [Haskell-cafe] Proposal: TypeDirectedNameResolution

2009-07-27 Thread John Dorsey
Cale et al,

I have a concern about the implementation of the proposed
TypeDirectedNameResolution.  (I'm not familiar with the internals of any of
the compilers, so it could be that my concern isn't well founded.)

I'm assuming that name resolution is currently independent of type
inference, and will happen before type inference.  With the proposal this is
no longer true, and in general some partial type inference will have to
happen before conflicting unqualified names are resolved.

My worry is that the proposal will require a compliant compiler to
interweave name resolution and type inference iteratively.

Give the Haskell source code:

  import X
  import Y
  import Z

  a = 1 + (1 :: Integer)
  b = x a
  c = y b
  d = z c
  .
  .
  .

Assume X, Y, and Z all export x, y, and z.  The compiler might do something
like this:

  (do stuff)
  Infer type of 'a'
  Resolve unqualified use of 'x' in x a
  Infer type of 'b' from b = x a
  Resolve unqualified use of 'y' in y b
  Infer type of 'c' from c = y b
  Resolve unqualified use of 'z' in z c
  etc.

If ambiguous unqualified names are used mutually recursively it may be that
there's only one reasonable combination of name resolutions, but is this
decidable?

To my untrained eye it looks complicated and invasive, even without the
mutually recursive case.  Can anyone shed light on whether this would be a
problem for, say, GHC?

Thanks,
John

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


Re: [Haskell-cafe] Circular pure data structures?

2009-07-14 Thread John Dorsey
John,

 Is it possible to create a circular pure data structure in Haskell?  For
 example:

Creating the data structure is easy; as other respondents have pointed out.
A simple example is this...

ones  = 1 : ones
ones' = 1 : ones'

Comparing these values is harder.  All of (ones), (ones'), (tail ones), and
so forth are equal values.  But I don't know how to compare them.  My
Spidey-sense tells me there's probably a simple proof that you can't, if you
care about the comparison terminating.

Pointer equality (ie. testing if the values are represented by the same
bits in memory) is no good, since it's entirely up to the compiler whether
ones and ones' use the same bits.  (They won't, but that's not important.)
In general pointer equality of Haskell values, such as ones and (tail
ones) interferes with referential transparency, which is held in high
regard around here.  Although, for the record, when pointer equality is
really what you want, I'm sure there's ways to Force It.

For your purposes, does it matter if you can actually do the comparison?  Is
it enough to know that ones and (tail ones) are equal?

Regards,
John

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


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

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

As another native English speaker, I found expected/inferred very
intuitive when I was new to GHC, and to Haskell.  I even think that
expected/inferred helped me form my intuition about Haskell's type
inference.

There was one hang-up; it wasn't at all clear which referred to the term,
and which referred to the context.  (Really both types are inferred.) This
stopped bothering me when I decided it didn't matter which was which, and I
could generally find the problem pretty quickly just knowing the location
and the types involved.

Of course, I can see how the messages are probably much less useful to
non-native speakers, and that's quite important.  Something along the lines
of inferred type droozle for term, but expected type snidgit in
context.

John

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


Re: [Haskell-cafe] [ANNOUNCE] Bindings for libguestfs

2009-05-12 Thread John Dorsey
Richard,

 I added some partial bindings for libguestfs[1] here:
 http://git.et.redhat.com/?p=libguestfs.git;a=blob;f=haskell/Guestfs.hs;hb=HEAD

Terrific!  Partial bindings are great.  Thanks for releasing it.  I haven't
taken the time to look at your code, but...

 BTW, I found the documentation on writing FFIs very contradictory and
 incomplete.  For example, I was completely defeated trying to find
 ways to do simple stuff like passing in integers or returning
 booleans.  *Potentially* Haskell's FFI seems like it might be one of
 the best out of the languages I've used so far, but it needs way more
 documentation and examples.

Can you be more specific about what needs improvement?

I wrote a partial Haskell binding for Net-SNMP recently, and I got along
pretty well using the API docs at
http://www.haskell.org/ghc/docs/latest/html/libraries/index.html, and an
example in RWH using hsc2hs.

What did you see that was contradictory?

Regards,
John

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


Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread John Dorsey
  Does that also mean that you could write:
 
  if 3 - 4 then ... else ...  (= if (fromInteger 3 :: Bool) - (fromInteger 4
  :: Bool) then ... else ...)
 
 No. 3 - 4 is an Integer, the proposal is to convert Bools to Ints, not
 Ints to Bools.

Rather, (3 - 4) is a (Num t) = t, so yes, this would work with instance
Num Bool.

  *Main if 3 - 4 then yessirree else yep
  yep

 Yeah, the more people give examples of the power of Num Bool, the more
 it seems like a very bad idea!

+1

John

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


Re: [Haskell-cafe] fromInteger for Lists

2009-05-01 Thread John Dorsey
Paul,

 There's nothing better than making a data type an instance of Num. In
 particular, fromInteger is a joy. But how about lists?

Do you mean something like Blargh below, only useful?

John


dor...@elwood:~/src/scratch$ cat list.hs 

class Blargh f where
  fromList :: [a] - f a

data Foo a = Foo [a] deriving (Show)
data Bar a = Bar [a] deriving (Show)

instance Blargh Foo where
  fromList = Foo

instance Blargh Bar where
  fromList l = Bar (reverse l)

dor...@elwood:~/src/scratch$ ghci list.hs
GHCi, version 6.8.3: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( list.hs, interpreted )
Ok, modules loaded: Main.
*Main fromList [1,2,3] :: Foo Int
Foo [1,2,3]
*Main fromList [1,2,3] :: Bar Int
Bar [3,2,1]
*Main 

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


Re: [Haskell-cafe] General function to count list elements?

2009-04-18 Thread John Dorsey
Michael,

 I had a count function that worked fine for an enum type, but thought
 why not go polymorphic with it. So I changed it and got the error I
 originally inquired about.

For variety, I'll go a slightly different direction.

If you generalize count to use any predicate, instead of always
equality...

gcount :: (a - a - Bool) - a - [a] - Int
gcount pred x0 xs = length (filter (pred x0) xs)

count = gcount (==)

This will work with any type that you can write a predicate for with the
type (a - a - Bool).  I can even use this with functions, if I'm
careful.

ghci gcount (\f g - True)   (*2) [id,(const 1),(*3)]
3
ghci gcount (\f g - f 1 == g 1) (^2) [id,(const 1),(*3)]
2

By the way, do you see why everyone's bothing you about comparing
functions?  The type you gave count, which didn't have an Eq constraint,
was an assertion that you could compare two values of *any* type.  If
there's a type that's not comparable, then count's type was wrong.
Functions are the canonical example of an incomparable type.

When you're bored some time, read a bit about the Curry-Howard
correspondence.  It's interesting, even if (like me) you don't grok all
of its implications.

Regards,
John

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


Re: [Haskell-cafe] Printing list of enum type

2009-04-14 Thread John Dorsey
Michael,

 What do I need to add to this Color enum type to print a list of them?

You can also easily print a list of /all/ of them.

Regards,
John

scratch$ cat color.hs 

data Color
    = Red
    | Blue
    | Green
    | Yellow
    | Orange
    | Brown
    | White
    | Black
  deriving (Show,Enum,Bounded)

scratch$ ghci color.hs 
*Main [minBound..maxBound] :: [Color]
[Red,Blue,Green,Yellow,Orange,Brown,White,Black]

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


Re: [Haskell-cafe] Re: Configuring cabal dependencies at install-time

2009-04-07 Thread John Dorsey
John Lato wrote:
 I think that the proper solution is to break up libraries into
 separate packages as Jeff suggests (buster, buster-ui, etc.), but then
 the total packages on hackage would explode.  I don't feel great about

I thought about this a while back and came to the conclusion that the
package count should only grow by a small contant factor due to this,
and that's a lot better than dealing with hairy and problematic
dependencies.

It should usually be:

  libfoo
  libfoo-blarg
  libfoo-xyzzy
  etc.

and more rarely:

  libbar-with-xyzzy
  libbar-no-xyzzy
  etc.

each providing libbar.  Although I don't remember whether Cabal has
'provides'.  The latter case could explode exponentially for weird
packages that have several soft dependencies that can't be managed in
the plugin manner, but I can't see that being a real issue.

This looks manageable to me, but I'm no packaging guru.  I guess it's a
little harder for authors/maintainers of packages that look like leaves
in the dependency tree, which could be bad.  Am I missing something bad?

Regards,
John

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


Re: [Haskell-cafe] Re: Configuring cabal dependencies at install-time

2009-04-07 Thread John Dorsey
Edward,

Thanks for straightening me out; I see the problems better now.  In
particular I was missing:

1)  Orphaned types (and related design issues) get in the way of
splitting the package.

2)  Viral dependencies work in two directions, since upstream packages
must pick up your deps to include instances of your classes.

I'm thinking out loud, so bear with me.

 The problem is there is no path to get there from here. Getting another
 library to depend on mine, they have to pick up the brittle dependency set I
 have now. Splitting my package into smaller packages fails because I need to
 keep the instances for 3rd party data types packed with the class
 definitions to avoid orphan instances and poor API design. So the option to

Some class instances can go in three places:

a)  The source package for the type, which then picks up your deps.  Bad.

b)  Your package, which then has a gazillion deps.  Bad.

c)  Your sub-packages, in which case they're orphaned.  Bad.

I have to wonder whether (c) isn't the least of evils.  Playing the
advocate:

-  Orphaned instances are bad because of the risk of multiple instances.
That risk should be low in this case; if anyone else wanted an instance
of, say, a Prelude ADT for your library's class, their obvious option is
to use your sub-package.

-  If you accept the above, then orphaning the intance in a sub-package
that's associated with either the type's or the class's home is morally
better than providing an instance in an unaffiliated third package.

-  Orphaning in sub-packages as a stopgap could make it much easier to
get your class (and the instance) added to those upstream packages where
it makes sense to do so.

This clearly doesn't solve all parts of the problem.  You may have other
design concerns that make sub-packages undesirable.  Even with instance
definitions removed you may still have enough dependencies to deter
integration.  The problem probably extends beyond just class instances.

 The only other alternative that I seem to have at this point in the cabal
 packaging system is to create a series of flags for optional functionality.

This sounds like rat hole of a different nature.  You lose the ability
to tell if an API is supported based on whether the package that implements
it is installed.  An installed and working package can cease to function
after (possibly automatic) reinstallation when other packages become
available.  Complicated new functionality is required in Cabal.

Regards,
John

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


Re: [Haskell-cafe] high probability of installation problems and quality of the glorious implementation

2009-04-05 Thread John Dorsey
Quoth FFT:
 My general null hypothesis is, as Alec Baldwin put it, that a loser is
 a loser, or a buggy project is buggy.

I can't see the world in such black and white terms.  GHC has strengths
and weaknesses, as do other projects.  GHC is changing over time, as are
other projects.

Formally verified software is still rare.  Most of the useful stuff lies
somewhere between buggy and bug-free.

 If GHC is robust overall (which I'm yet to find out), why is the
 installation so broken?

History.  Limited resources.  Complexity and diversity of target
environments.  Moving targets.  Day jobs.

Of course, you have to determine what your needs and standards are for
any product you use.

Regards,
John

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


Re: [Haskell-cafe] Function to cast types

2009-03-22 Thread John Dorsey
Anonymous One,

 I'm new to haskell, I'm wondering how can you write a function that will do
 the following:
 fromIntToString :: Int - String

Is this a homework assignment, perchance?  Please take a look at
http://www.haskell.org/haskellwiki/Homework_help
Everyone here is glad to help, but we're also sensitive on academic
honesty.

With that said, you've done the first step, which is writing down the
function's type.  You don't want to iterate over all possible Int
values, so maybe a recursive definition is in order.  What are the cases
to consider?  Like, what happens if you have a negative number...

 this is a cast function to cast an Int to a String. I know such function

By the way, cast is probably the wrong word for what you want.  You're
building a string representation of an Integer; in my view it's not just
a type conversion.

Good luck,
John

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


Re: [Haskell-cafe] Function to cast types

2009-03-22 Thread John Dorsey
Rafael Cunha de Almeida wrote:

 This e-mail is offtopic, but I suppose being a little offtopic every now
 and then isn't that bad, specially if the subject is interesting. So,
 here I go.

It's the cafe'.  Very little is strictly off-topic here, and certainly
not this.

I'm happy to help anyone who's trying to learn, but I will not willingly
subvert anyone's classroom rules, as a matter of academic honesty.  I
think that matters at any level of school.  I accept that it can't be
enforced perfectly, or anywhere near so.

I didn't mean to accuse the original poster, and I trust I didn't come
accross that way.  I don't think it's a bad idea to point out that an
anonymous question like this one may look suspicious, or that many
instructors follow this forum.  None of that should give offense.

But I also provided some hints.  I think a good and fun way to help with
problems like that is to iteratively guide someone to their answer,
instead of giving it to them straight-up.

Just to be clear, I also have no criticism of the other replies.  Anyone
giving voluntary help should and will apply their own rules.

 The only reason people would want the answer of an assignment instead of
 actually doing it themselves is if they don't care about actually doing
 it. That is, they don't want to learn haskell, they just want to pass a
 class. In that case, do we really want to _make_ them learn?

In that case I have no interest in forcing them to learn or in helping
them get a grade.  But I'm always optimistic that someone's willing to
learn.  I've been proven wrong, but not often.

Cheers,
John

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


Re: [Haskell-cafe] Re: [Haskell-beginners] folds -- help!

2009-03-14 Thread John Dorsey
Adrian,

 That's why I said for appropriate g and f. But I see that my  
 wording was misleading.

Thanks for following up!  I had thought you were arguing that foldl and
foldr were easily and intuitively interchangeable; they're surely not so
for beginners.

Now I think you're arguing that given strict oplus, each can be generally
expressed in terms of the other, allowing for different space/time
complexity.

Thanks for clarifying.  I should have paid more attention to your
appropriate g and f qualifier.

Cheers,
John

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


Re: [Haskell-cafe] Haskell users in the Houston area??

2009-02-18 Thread John Dorsey
Vasili,

  Are there Haskell users in the Houston area?

At least one, but I'm behind on my cafe' reading.  smiley

Cheers,
John

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


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

2008-12-24 Thread John Dorsey
Quoth Miguel Mitrofanov:
 You have to be unnecessarily strict to read the whole word Haskell  
 and not just first one or two letters.

Not true, if you're looking forward to what may follow Haskell.

Cheers,
John

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


Re: [Haskell-cafe] Linking and unsafePerformIO

2008-10-14 Thread John Dorsey
Jules Bean wrote:

 I'm saying that we can change programs, and that changes their 
 denotation, and that's fine, and anyone can do that. But the denotation 
 of a program is supposed to be something independent of a particular 
 compiler or OS or MAC address or RAM size or any of the millions of 
 other things which probably don't change during the single run of a program.

And native Int size.  Should all Int's be in the IO Monad?
Should all floating point numerals be in the IO Monad?

Does your proposal push all non-portability into IO, making the
non-IO subset of Haskell a portable virtual machine specification?

Regards,
John

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


Re: [Haskell-cafe] [] vs [()]

2008-10-09 Thread John Dorsey
 dmehrtash:
 What is the difference between empty list [] and list with one unit
 element [()]?
 
 Prelude length []
 0
 Prelude length [()]
 1

Also, they differ in type.

[()] is a list of unit elements, and happens to contain exactly one
of them.

[] is a (polymorphic) list of any kind of element, and happens not to
contain any of them.

Regards,
John

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


[Haskell-cafe] Announcing OneTuple-0.1.0

2008-10-02 Thread John Dorsey
Fellow Haskellers,

Much attention has been paid over the years to the regrettable
omission of singleton tuples from Haskell.

I am pleased to announce OneTuple, a humble implementation of the
singleton tuple for Haskell.  Now you can:

*  Wrap a single value of any type in a OneTuple !

*  Pattern match to retrieve your value !

*  Solve any of the software problems that cannot be solved without
   the singleton tuple !

*  Enjoy instances for all the classes normal tuples have, plus more !

*  Proclaim feature parity with Python !

Note:  the singleton tuple does not support tuple syntax.

Contributions are welcome.  The project could use a tutorial, and a
decent test suite.  Strict singleton tuples are planned for the next
version.

Enjoy!

Regards,
John Dorsey

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


Re: [Haskell-cafe] Announcing OneTuple-0.1.0

2008-10-02 Thread John Dorsey
All,

I'm bundling responses to save paper.

[EMAIL PROTECTED] wrote:
 I hope it has a Monad instance.

Naturally!

 But more to the point: Can it send email?

Can you give an example of a use case?  Do the Haskell-98 standard
tuples have a correspondence feature?  I wasn't able to find one with
Hoogle.

Simon Brenner wrote:
 You could always use this one-tuple instead and get Functor, Monad and
 MonadFix for free:

As Luke pointed out, that one seems to be too strict.  It may simplify
the strict implementation, though.  The initial release did have Monad
and Functor instances... I'll look into MonadFix (thanks!).

Luke Palmer wrote:
 Hmm, it looks like you forgot to write a Traversable instance.

Oops... I included the instance statement but retained the default,
mutually recursive methods.  Too bad GHC didn't warn me.  (Pesky
halting problem.)  Your change is in 0.1.1 -- thanks!

Benjamin L.Russell wrote:
 Wonderful!  I'm intrigued

Thank you.

 What is the syntax for the singleton tuple?  [...]  What is your
 solution?

Haskell has no such syntax, of course.  '(x)' is no good due to
ambiguity with parens' usual associative use.  '(x,)' has been
discussed, I think.  It's ugly; it's inconsistent with other tuples,
which don't share its final comma; it looks a bit like a tuple section,
which could cause confusion.

My solution was to use a normal Algebraic Data Type:
data OneTuple a = OneTuple a

I think the need for singleton tuples is rare enough that the
syntactic inconsistency is tolerable.

Jon Fairbairn suggests using unicode 0x27e8 and 0x27e0 in place of
parentheses for tuples.  I like the idea, especially as an alternate
syntax for the same tuple types, permitting the singleton.

minh thu writes:
 I thought to this idea in another way : parenthesis could be used for
 s-expressions and [unicode 0x27e8 and 0x27e0] could be used for
 regular grouping. This would allow to switch in the same code between
 infix and s-expr (e.g. enabling SXML)...

I don't think I fully understand your proposal, although it sounds
interesting.

Regards,
John Dorsey

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


Re: [haskell-cafe] Monad and kinds

2008-09-05 Thread John Dorsey
Tim,

   A year or two ago, ISTR that *most* of the newbie-generated traffic in
   the cafe was about atrocious performance of naive programs due to
   strict/lazy concerns.  I think it was scaring people away.
 
 I think it's debatable what the various causality relationships might be here.

Certainly...

   Adding strictness can improve asymptotic space performance, as an example.
   Is there a reason to think this won't always be true?  Honest question,
   since I don't know nearly enough about strictness analysis to guess
   how good it'll be some day.
 
 Adding strictness can also worsen asymptotic space (and time)
 performance. That's one reason why we use a lazy language at all.
 Strictness analysis is an approximation to the problem of determining
 what parts of a program can be evaluated strictly without changing
 their meaning, because if we had a perfect solution to that problem,
 we could solve the halting problem.

No argument.  I was responding to your comment that ...

IMO, arguing that programmers should care at all amounts to
 conceding that default laziness is treacherous.

... which sounds like you're arguing against programmers giving due
attention to lazy/strict choices.  I was suggesting that there is good
reason to think that we should pay attention to it; that it's a
necessary part of learning Haskell; and that it will likely remain so.

Newbies should be encouraged to think and experiment more with
laziness and strictness.

Regards,
John
(pondering an IDE mode for visualizing strictness properties)

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


Re: [haskell-cafe] Monad and kinds

2008-09-04 Thread John Dorsey
Tim Chevalier wrote:
 I'm no master, but I've never encountered a situation where strictness
 annotations would be useful as documentation, nor can I imagine one.
 That's because optimization *is* the only reason why programmers
 should care about strictness information. IMO, arguing that
 programmers should care at all amounts to conceding that default
 laziness is treacherous.

I'm no master either, but I'd argue that if we promise new programmers
that they don't need to care about strictness, we thereby ensure that
default laziness is treacherous.

A year or two ago, ISTR that *most* of the newbie-generated traffic in
the cafe was about atrocious performance of naive programs due to
strict/lazy concerns.  I think it was scaring people away.

Adding strictness can improve asymptotic space performance, as an example.
Is there a reason to think this won't always be true?  Honest question,
since I don't know nearly enough about strictness analysis to guess
how good it'll be some day.

Regards,
John

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


Re: [Haskell-cafe] unsafeInterleaveIO, lazyness and sharing

2008-08-26 Thread John Dorsey
Wolfgang,

 Haskell is non-strict but not necessarily lazy.  So it's possible
 that an expression is reduced to WHNF although it is not used yet.
 Could this early reduction also happen to outputs of
 unsafeInterleaveIO actions (which might trigger the action too early)?
 While I'd expect those outputs to be evaluated lazily (reduced as
 late as possible), I cannot find anything in the docs that guarantees
 this.

unsafeInterleaveIO allows IO computation to be deferred lazily. When
passed a value of type IO a, the IO will only be performed when the
value of the a is demanded. This is used to implement lazy file reading,
see hGetContents.

http://haskell.org/ghc/docs/latest/html/libraries/base/System-IO-Unsafe.html#v:unsafeInterleaveIO

Is this the kind of guarantee you're looking for?

I'd bet against getting any decent durable, portable guarantees for any
unsafe* functions in Haskell; but the above behavioral description may
be strong enough to suit you.

 In addition, I'd like to know whether unsafeInterleaveIO outputs are 
 guaranteed to be evaluated at most once so that the interleaved action is 
 executed at most once.  Again, I suppose that this is the case while I cannot 
 find a guarantee for it.

I'd be surprised if an implementation didn't have that behavior.

I'd also be wary of anyone claiming to guarantee it, beyond compiler X
version Y.

John Dorsey

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


Re: [Haskell-cafe] Cabal + yi + alex problem.

2008-07-30 Thread John Dorsey
 [problems with cabal install yi]

Curious, I tried this out, on a Debian etch box with GHC 6.8.3.

cabal update ; cabal install yi --global
complained about needing alex =2.0.something and 3.

Then cabal install alex happily installed alex version 2.2.  Finally,
cabal install yi --global worked fine.

Is something amiss with cabal-install?  Shouldn't it have automatically
installed alex?  Or does it only do that with libraries, by design?

For that matter, ghc-pkg list | grep -i alex doesn't list anything,
after I cabal-installed it.  How does cabal verify the prerequisite alex
version?  (Or does it?)

I'm enjoying cabal since I've begun using it, but it's still somewhat
opaque to me.

Regards,
John Dorsey

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


Re: [Haskell-cafe] Another optimization question

2008-05-17 Thread John Dorsey
Jeroen,

 isPrime :: Int - Bool
 isPrime x = isPrime' x primes
 where isPrime' x (p:ps) | x == p = True
 | x  p = isPrime' x ps
 | otherwise = False
 
 main = print $ length (filter (== True) (map isPrime [1..5000]))
[...]
 isPrime x = elem x (takeWhile (= x) primes)

Here's a couple of things, although I don't know if they account for what
you're seeing.  All code is untested.

1)  A simpler main would be:

main = print $ length $ filter isPrime [1..5000]

This version manually fuses your map and filter.  Of course it's not
the same if you're doing anything else besides 'length'.

2)  The takeWhile in your second isPrime creates a throwaway list, which
doesn't exist in the explicit-recursion isPrime.  Unless this gets
optimized out, this could be the droid you're looking for.  I'd compile
with profiling (ghc -O2 --make -prof -auto-all experiment2), and run
./experiment2 +RTS -p -s
Find profiling stats in experiment2.prof, and check whether the latter
version isn't allocating a lot more.  When you feel like Core-diving,
it's something specific to look for.

3)  Maybe you can get the best of your two versions -- meaning the
relative speed of the first and functional style of the second -- by
writing your own 'elem' replacement that works on a sorted list.
Something like this, with suitably defined elemAsc:

-- elemAsc: tests presence of element in an ascending list
elemAsc :: (Ord a) = a - [a] - Bool
elemAsc ...
isPrime x = elemAsc x primes

Here's a good habit:  abstract things like this out.  Read the
libraries, and look for better and more abstract patterns.
Rinse, repeat.

4)  This doesn't explain why the version with real primes was 10x slower.
Are you comparing apples to apples?  Specifically, comparing both
versions of isPrime above using real primes, so both of them have to
create the primes list?  Does your code for real primes still use [Int]
and not [Integer] or (Num t) = [t] ?

I haven't invested the time yet to stare at GHC Core until it clicks,
excepting a few snippets that have been discussed here.  I'm not sure
how early in the learning curve it's advisable.  Probably depends on
your background.

Good luck Eulering,
John

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


Re: [Haskell-cafe] deriving

2008-04-07 Thread John Dorsey
Paul,

 Hi
 data Bool = False | True
   deriving (Eq, Or, Show, Read)
 
 Bool is an instance of Eq, Ord, Show and Read. It is derived form 
 these classes.

No.  deriving ... here does not mean that Bool is derived from those
classes; it's not a statement about inheritance or anything similar.

deriving ... means that the class instances for Bool, for those four
type classes, are automatically derived from the definition of Bool.

Does this make more sense?

John

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


(forw) Re: [Haskell-cafe] deriving

2008-04-07 Thread John Dorsey
I meant to send this reply to the cafe.

- Forwarded message -

Date: Mon, 7 Apr 2008 15:05:00 -0400
To: PR Stanley [EMAIL PROTECTED]
Subject: Re: [Haskell-cafe] deriving

Paul,

 No, sorry. I'm not sure how this differs from my definition. 
 Could you elaborate please?

Gladly.  I haven't tested any of the code below, so pardon any typos
and thinkos.

It sounded like you were trying to say that Bool derives from Eq, Ord,
Show, and Read, and thus the keyword from would apply.  Of course,
I may have misunderstood your intent.

I was countering by saying that the deriving keyword indicates something
different.  I'll try to describe what I meant in a little more detail.

A type class definition defines properties of the type class.  Eg.,

class Example a where
foo :: a
bar :: a - a

The class is then related to specific types by giving them instance
declarations.  The instance declarations can be explicit, as in

data Xyzzy = Xy | Zzy
instance Example Xyzzy where
foo = Xy
bar = const Zzy

Sometimes the instance declaration can be automatically derived instead,
which looks like:

-- non-working code, see below
data Xyzzy = Xy | Zzy
deriving (Example)

This lets the compiler derive the obvious class instance declaration.
But it won't work for just any class, because the compiler needs to know
how to derive obvious instances.  A few classes have deriving
machinery built-in:  Eq, Ord, Enum, Bounded, Show, Read.  

deriving (Example) won't work, since that machinery doesn't exist.

With effort, you could implement this automatic derivation machinery
for your own types, at least in GHC.  I've never needed it, so I've
never learned exactly how to do it.

In short, so data Foo [...] deriving (Eq) means: define a new type Foo,
and automatically derive its class instance for Eq.

Does this help?

Regards,
John

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


Re: [Haskell-cafe] Re: ANNOUNCE: GHC version 6.8.2

2007-12-23 Thread John Dorsey
Judah,

Thanks for your reply, and your help.

  (Although it looks like the libraries/readline/configure script
  might recognize these, I can't get an option to pass through.)
 
 Actually, this is supposed to work.  When running the top-level ghc
 configure, you should be able to just say
 ./configure --with-readline-libraries=/opt/local/lib
 --with-readline-includes=/opt/local/include
[...]
 I just checked that this works on my machine (Tiger x86) when building
 6.8.2 against MacPorts' readline.  If it doesn't work for you, what
 errors are you getting?

I was slow to reply, in part so I could try this again with a fresh
start from the tarballs.  Sure enough, it now works for me.

What I /was/ seeing was a successful compile and install of ghc, but no
readline functionality in ghci (i.e. backspaces gave me junk).

 Also, a couple of other generic questions:
 - Are you on x86 or PPC?  (The latter is not working right yet with Leopard.)

I have both, but I've been using the x86.

 - How are you bootstrapping the build of 6.8.2: are you using a
 pre-built binary of ghc-6.8.1, or some other way?

Yep, a binary distro of 6.8.1 was right.

I must have failed to dot an 'i' somewhere before.  Thanks for pointing me
in the right direction.

John

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


[Haskell-cafe] Re: ANNOUNCE: GHC version 6.8.2

2007-12-21 Thread John Dorsey
(Moving to the cafe)

On a related topic, I've been trying to build 6.8.2 on Leopard lately.
I've been running up against the infamous OS X readline issues.  I know
some builders here have hacked past it, but I'm looking for a good
workaround... ideally one that works without changes outside the GHC
build area (besides installing a real readline).

Here's what I noticed before I started drowning in the build platform.
(I'm no gnu-configure expert nor GHC insider.)

I can get gnu-readline installed from Macports, no problem.

The top-level configure in GHC doesn't respond to my various attempts:

o  using --with-readline-libraries and --with-readline-includes
(Although it looks like the libraries/readline/configure script
might recognize these, I can't get an option to pass through.)
o  setting LDFLAGS and CPPFLAGS environment variables (with
-L/opt/local/lib and -I/opt/local/include resp.) in my shell
before running configure
o  playing with the above settings and others in a mk/build.mk

Until Apple fixes their broken-readline issue (maybe when the readline
compatibility of libedit improves)... maybe the top-level configure can
pass through flags or settings somehow?

For those who've built with readline on OS X:  have you had to resort to
blasting the existing readline library link, or is there a configuration
option within the GHC tree that you've gotten to work?

Should I be filing a trac bug instead of asking here?

Thanks for any help.  There's no urgency for me; I'm just trying to get
a working environment at home; I'd prefer to be able to bootstrap from
the ground up; and I'd like to be able to contribute to testing/debugging
on OSX.

John

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