Re: [Haskell-cafe] quiry

2007-05-16 Thread Pixel
ashutosh dimri [EMAIL PROTECTED] writes:

 how to convert a hexadecimal into base 10 integer using haskell . I have
 written a code but its not working for large values , please help

from http://pleac.sourceforge.net/pleac_haskell/numbers.html#AEN118 :


-- read handles both octal and hexadecimal when prefixed with 0x or 0o
-- here are versions adding the prefix and calling read
hex s = read (0x ++ s) :: Integer
oct s = read (0o ++ s) :: Integer

-- hex 45 == 69
-- oct 45 == 37
-- hex 45foo = Exception: Prelude.read: no parse

-- calling explicitly readHex or readOct:
hex = fst . head . Numeric.readHex
oct = fst . head . Numeric.readOct

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


[Haskell-cafe] Re: Tutorial on Haskell, PLEAC

2007-04-16 Thread Pixel
Simon Peyton-Jones [EMAIL PROTECTED] writes:

 I'm quite excited about this: it is a great opportunity to expose Haskell to a
 bunch of smart folk, many of whom won't know much about Haskell. My guess is
 that they'll be Linux/Perl/Ruby types, and they'll be practitioners rather
 than pointy-headed academics.

 One possibility is to do a tutorial along the lines of here's how to reverse
 a list, here's what a type is etc; you know the kind of thing. But instead,
 I'd prefer to show them programs that they might consider *useful* rather than
 cute, and introduce the language along the way, as it were.

As for me I find quickCheck a killer feature, and quite concise.


While on the subject, i'd like to mention that at last PLEAC now has a
standard haskell version:

http://pleac.sf.net/pleac_haskell

of course, it's still a long way to go: only 9% is done, nice comments
should be added, better code... But it's quite useful already!

(i know pleac is somewhat a duplicate of
http://haskell.org/haskellwiki/Cookbook, and it's not always adapted
to haskell, but i still think it's quite useful and worth working on
it. i suggest it's time to remove the pleac bashing from
http://haskell.org/haskellwiki/Cookbook)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Foldr tutorial, Inspired by Getting a Fix from a Fold

2007-02-12 Thread Pixel
Chris Moline [EMAIL PROTECTED] writes:

 dropWhile p = foldr (\x l' - if p x then l' else x:l') []

invalid:  dropWhile ( 5) [1, 10, 1]  should return [10, 1]
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Paths to tree

2007-01-31 Thread Pixel
Bulat Ziganshin [EMAIL PROTECTED] writes:

 btw, are you seen http://haskell.org/haskellwiki/Simple_unix_tools ? :)

: This is intended as a beginners tutorial for learning Haskell from a
: Lets just solve things already! point of view. The examples should
: help give a flavour of the beauty and expressiveness of Haskell
: programming.
:
: --
: -- Some unix-like tools written in simple, clean Haskell
: --
: --
:
: [...]
: showln  = (++ \n) . show

maybe it should be mentioned in the page that it needs
-fno-monomorphism-restriction?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell Cookbook?

2007-01-31 Thread Pixel
Dougal Stanton [EMAIL PROTECTED] writes:

 Hmm, that doesn't make a whole lot of sense, but you see what I'm
 getting at. The cookbook approach is great; it's a real shame that the
 one Haskell cookbook implementation out there (it was a reworking of a
 perl book I think? I can't remember the name) was barely recognisable as
 Haskell at all. I think the entire Prelude had been hidden and all the
 operators redefined as other things. Maybe it would be useful to start
 on that, but using idiomatic Haskell rather than obfuscated Haskell.

(about http://pleac.sf.net/)

pleac is coming along quite nicely, with some active contributers
(ocaml, groovy...)

as for the haskell entry, Yoann Padioleau wanted to show haskell could
be very expressive, so he introduced many new functions/operators. The
haskell entry should be renamed because it's really a domain specific
embedded language :-)
(see http://pleac.sourceforge.net/pleac_haskell/a1102.html)

But this does not follow the pleac goal, which aims at showing how to
do something the standard way. I'm planning to contribute a new
haskell entry to pleac, based on Yoann's, but getting rid of the all
the wonderful weird stuff, ie plain old haskell :)
If someone wanna do it before me (since alas i can't allocate much
time on it), please do!

--
Pascal Rigaux - http://merd.net/pixel/language-study/syntax-across-languages
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANNOUNCE: The Monad.Reader - Issue 6

2007-01-31 Thread Pixel
Wouter Swierstra [EMAIL PROTECTED] writes:

 * Bernie Pope - Getting a Fix from the Right Fold

i ended up with this one:

dwBool predicate l = (foldr combine (\_ - []) l) True
where 
  combine e fl beg = if beg  predicate e 
 then fl True 
 else e : fl False

higher-order, like solutions 3  4, but simpler IMO :p
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] pleac, examples, etc

2006-11-14 Thread Pixel
Spencer Janssen [EMAIL PROTECTED] writes:

 Please do not use the PLEAC Haskell cookbook for learning Haskell.   The
 author redefined many of the standard operators to produce code  that isn't
 standard Haskell.

 Here are some choice snippets from the first chapter:

 Now, we all know that the (.) operator is function composition,  right?  Not
 in this example!  The author has silently defined (.) =  flip ($) -- a sort
 of reverse function application.
 cut2fmt xs = xs.foldl aux (1,[]).snd.(GrabAll:).reverse

 Ah yes, (^) is surely exponent here?  Nope, it's some kind of unholy
 combination of show and (++).
 s9 = I have ^10+1^ guanacos.

 More of the same:
 piece = s!![-8 .. -5]


 Complaining aside, I do agree with you: we need more example-style
 documentation.  Rewriting the PLEAC cookbook might be a good start.

i agree. A friend of mine did this haskell PLEAC version, and i would
really like to have a /standard/ haskell one.
(alas i've no more time to do it myself...)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] preffered 'map'

2005-12-09 Thread Pixel
Benjamin Franksen [EMAIL PROTECTED] writes:

 import Data.Map as Map

 but now anywhere when I want ot use map it complains for
 name clashes, so I have to specifiy Prelude.map all the time.
 Is there a way to specify that i mean Prelude not Data 'map' (but not
 fqn) I use Hugs, 'cause error messages are more understandable.

 import Data.Map as Map
 import Prelude hiding (map)
 import qualified Prelude (map)

better do:

  import qualified Data.Map as Map

since:

  import A as B x, y, B.x, B.y
  import A as B(x)  x, B.x
  import qualified A as B   B.x, B.y

(cf http://www.haskell.org/onlinereport/modules.html)

i've been hit by this too.
maybe the documentation at beginning of Map.hs should be changed?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: ICFP programming contest

2003-01-03 Thread Pixel
[EMAIL PROTECTED] writes:

 Michael Hobbs writes:
   Just took a look at the results for the ICFP contest. Am I correct in
   assuming that LA stands for Lennart Augustsson and that Si^3 stands
   for Simon Marlow, Simon Peyton-Jones, Sigbjorn Finne?
 
 Is there a URL for the results ?

google would give you: http://icfpcontest.cse.ogi.edu/

see also: http://merd.net/pixel/language-study/icfp-figures.html
(shameless advertising)
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: Monad Maybe?

2002-09-21 Thread Pixel

Russell O'Connor [EMAIL PROTECTED] writes:

 [To: [EMAIL PROTECTED]]
 
 Is there a nicer way of writing the following sort of code?
 
 case (number g) of
  Just n - Just (show n)
  Nothing -
   case (fraction g) of
Just n - Just (show n)
Nothing -
 case (nimber g) of
  Just n - Just (*++(show n))
  Nothing - Nothing

what about?

 listToMaybe $ mapMaybe (\ (f, format) - fmap format (f g)) l
 where l = [ (number, show), (fraction, show), (nimber, (\ n - * ++ show n)) ]

or:

 if_just (number g) show $
 if_just (fraction g) show $ 
 if_just (nimber g) (\ n - * ++ show n) Nothing

using:

if_just (Just e) f _ = Just(f e)
if_just Nothing _ f = f
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: [Fwd: F#]

2002-05-31 Thread Pixel

Don Syme [EMAIL PROTECTED] writes:

 One point is that in the absence of extensive purity annotations to imperative
 libraries you will need to use monads for operations that shouldn't need them.
 Having to add the annotations certainly counts as a complication in comparison
 to what many other languages have to do on .NET.

am I wrong to think that

  would .NET had const'ness a la C++, purity annotations wouldn't be
  needed?

hum, not really. const methods can still modify global state (but not
object state)... but at least no need to annotate non-const methods :)



off topic:
 On the subject of const'ness, I've been messing around with it.
 I've been quite surprised to discover that JavaC# do not have C++'s
 const (Java has final on parameters, but it is dumb)

 About this: http://merd.net/inoutness.html 
 (beware, half of it is still investigations)
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: deriving over renamed types

2002-04-08 Thread Pixel

Ashley Yakeley [EMAIL PROTECTED] writes:

[...]

   -- which of these types are the same?
   f1 = MkFoo undefined :: Foo Succ;
   f2 = MkFoo undefined :: Foo Succ';
   f3 = MkFoo undefined :: Foo Succ'';
   f4 = MkFoo undefined :: Foo (Add (Succ Zero));

yeah, why not! Have them all be the same thing.
(i added the missing Foo on f4)


add Zero b = b
add (Succ a) b = Succ (add a b)

mult Zero b = Zero
mult (Succ a) b = add b (mult a b)

fact Zero = Zero
fact (Succ n) = mult (Succ n) (fact n)

data Foo f = MkFoo (f ())

succ' = Succ
succ'' n = Succ n

-- which of these types are the same?
f1 = MkFoo undefined :: Foo Succ
f2 = MkFoo undefined :: Foo succ'
f3 = MkFoo undefined :: Foo succ''
f4 = MkFoo undefined :: Foo (add (Succ Zero))


add to haskell
- eta-expanding of (add (Succ Zero)) in (\x - add (Succ Zero) x)
- compile-time evaluation of type expressions (handling unbounded parameters
like x above)

and that should do it!


I don't think this is a crazy as it sounds. Cayenne has already started
computing types at compile-time.

I'm currently working on merd (http://merd.net) which has a such a type system.
eg:

range(n, m) =
if n  m then
n | range(n + 1, m)
else
n

Two_to_height = range(2, 8)  #= 2|3|4|5|6|7|8

restricted_identity !! Two_to_height - Two_to_height
restricted_identity(x) = x

restricted_identity(4) #= 4
restricted_identity(1) #= compile-time error: 1 is not in 2|3|4|5|6|7|8
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: finding ....

2002-03-20 Thread Pixel

D. Tweed [EMAIL PROTECTED] writes:

[...]

  Could someone post an example of the creation of a
  temporary file where race conditions are important?
 
 myscript wants to create a temporary file called /tmp/storedStuff
 being half-careful, checks file doesn't exist
 (*) miniscule delay occurs
 creates a new file called /tmp/storedStuff

and of course, the solution is to open(file, ... | O_EXCL | O_CREAT)

that way if someone wants to trick you it fails nicely, and in other cases
everything is nice :)

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: finding ....

2002-03-19 Thread Pixel

Lennart Augustsson [EMAIL PROTECTED] writes:

 Just because many applications use this doesn't make it safe or good.
 Presumably you are testing for the existence of the file to do something
 to it (read, create, delete...).  It's better to do the operation you want to
 do and have it fail if the file is missing (or existing if you create).  You
 then just have to handle the exception (that part is already in H98) or
 proceed with the normal path.  I claim the code simpler this way and you
 avoid any race conditions.

I said real-world pbs ;p

WARNING, perl below!

- checking if devfs is mounted in /dev: -e /dev/.devfsd
- checking wether there is cdrom drive with devfs: -e /dev/cdroms/cdrom0
- looking for a file in a PATH-like:
  if ($f !~ m|/|) { -e $_/$f and $f = $_/$f, last foreach @icon_paths }
- 
  if (-e $f.gz) {
 # ... the wanted file is gzip'ed, doing whatever is needed
  }

- 
  -x /bin/sh or die cannot open shell - /bin/sh doesn't exist;
  fork and return;
  # doing things
  # now, and only now exec'ing
  exec /bin/sh

-
  if (! -e '/usr/sbin/showmount') {
  my $pkg = 'nfs-utils-clients';
  $in-ask_okcancel('', _(The package %s needs to be installed. Do you want to 
install it?, $pkg), 1) or return;
  $in-do_pkgs-install($pkg);
  }

If you want some more, just ask ;)
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: declaring a generic type in type synonyms

2002-02-21 Thread Pixel

Andre W B Furtado [EMAIL PROTECTED] writes:

 Is is possible to declare a generic type without using data or newtype?
 For example, I woud like that pair is a type synonym for (t,t) where t
 is a generic type, but just saying:
 
  type pair = (t,t)
 
 won't work: i get a parse error.

- types in haskell must be capitalized (maybe a better syntax error message
would be nice, i ran into the same pb)

- t is a free variable, so you can't write this. Either write:

type Pair t = (t,t)
or
type Pair = (Int,Int)
or even
type Pair t1 t2 = (t1, t2)
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: syntax across languages

2002-02-12 Thread Pixel


[...]

 (I guess its a cousin to templates in C++)
 Or perhaps you need a separate section for syntax
 for constructing new datatypes..

yes, i think so. With enums and ranges being a special case.

i'll also put records

[...]

 (Please dont take this as an insult by my re-explaining these things.
 I just want to make myself clear.)

the pb is that the semantic is so different between the languages. So i just
put all of them with no explaination.

   Under constrol structure, at least give mention to monads!
   Common examples (ST,IO,List,Maybe) and do notation
  
   Monads are defined by instanciating them under the Monad type class.
   (basically giving definitions for the operators = (aka 'bind') and 
 
  please be more precise, what do i put? in which category?
 
 I guess I suggested control structure because in a way, you can control
 the flow from a semantic point of view of your program by building /
 choosing a specific monad.  For instance, usage of the List monad brings
 nondeterminism into the language (although, in reality,
 the multiple solutions alluded to by the term are elements of a
 deterministically (is that a word?!) produced list)

syntax across languages is about syntax!

If something needs much explaination, it can't be included :p

[...]

 I suppose a sollution to what to do with do-notation is to put something
 like
 [...]
 or do {stmnt; var -stmtn; etc}
 
 under your section named Various Operators with description
 do statments under monad

I don't accept entries where only one language fits in :p

(this may change as soon as monads appear in more languages)

[...]

   References arent missing.  They are implemented under both the ST and IO
   monads.
 
  what is the syntax?
 
 no syntax, only functions which create/manipulate them (under some monad).
 
 do{ x-newSTRef exp; y -readSTRef x; writeSTRef x exp}
 
 for IORefs do s/ST/IO/g to above line.

eurk

ERROR /usr/share/hugs/lib/exts/ST.hs:48 - Syntax error in type expression 
(unexpected `.')

isn't there a way ST.hs would require the extensions? a pragma or something?
someone not knowing the -98 would wonder for a long time about what to do
:-(


anyway, the simplest examples i found:

show $ runST (do { x - newSTRef 2; writeSTRef x 3 ; readSTRef x })

so i can write:

newSTRef  in reference (pointer) creation
readSTRef writeSTRef  in reference (pointer) dereference

WDYT?


PS: show $ runST $ do { x - newSTRef 2; writeSTRef x 3 ; readSTRef x }
  is not working :'-(
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



syntax across languages

2002-02-10 Thread Pixel

http://merd.net/pixel/language-study/syntax-across-languages.html

CHANGES:
- the page has now much more entries
- one can check the missing entries per language at
  http://merd.net/pixel/language-study/syntax-across-languages-per-language.html
  (160KB)
  see especially the haskell one
  
http://merd.net/pixel/language-study/syntax-across-languages-per-language.html#Haskell


Contributions, suggestions and fixes are welcome.


--
Pixel
programming languages addict  http://merd.net/pixel/language-study/
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: ghci panic (unknown symbol stg_gc_l1)

2002-01-28 Thread Pixel

Julian Seward (Intl Vendor) [EMAIL PROTECTED] writes:

  % ghci
  [...]
  Loading package std ... linking ... 
  /usr/lib/ghc-5.02.2/HSstd.o: unknown symbol `stg_gc_l1'
  ghc-5.02.2: panic! (the `impossible' happened, GHC version 5.02.2):
  can't load package `std'
  [...]

 There's something very suspicious here, but it might be a
 bug we know about.
 
 Did you build ghc yourself, from sources?

yes

 Did you bootstrap using itself?

no, that is the pb. Sigbjorn Finne gave the explaination:

  GHCi doesn't load the RTS package (nor GMP),
  as they're both baked into the binary. My guess is that
  you've built ghci using 5.02.1; you need to use 5.02.2
  (i.e., do two stage build.)  The missing symbol was
  introduced in 5.02.2's RTS.

i bootstraped using itself, and now it works nicely :)

 And finally, exactly what version of gcc do you have?

an heavily patched 2.86

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



ghci panic (unknown symbol stg_gc_l1)

2002-01-26 Thread Pixel

% ghci
[...]
Loading package std ... linking ... /usr/lib/ghc-5.02.2/HSstd.o: unknown symbol 
`stg_gc_l1'
ghc-5.02.2: panic! (the `impossible' happened, GHC version 5.02.2):
can't load package `std'
[...]


(it seems) it should load package rts before std, but (it seems) it doesn't:


% for i in /usr/lib/ghc-5.02.2/*.o; do nm $i | grep -q T stg_gc_l1  echo $i; done
/usr/lib/ghc-5.02.2/HSrts.o

% ghci -v5
[...]
Using package config file: /usr/lib/ghc-5.02.2/package.conf
[...]
Package
   {name = std,
import_dirs = [/usr/lib/ghc-5.02.2/imports/std],
source_dirs = [],
library_dirs = [/usr/lib/ghc-5.02.2],
hs_libraries = [HSstd],
extra_libraries = [HSstd_cbits],
include_dirs = [],
c_includes = [HsStd.h],
package_deps = [rts],
extra_ghc_opts = [],
extra_cc_opts = [],
[...]
Loading package std ... linking ... /usr/lib/ghc-5.02.2/HSstd.o: unknown symbol 
`stg_gc_l1'


strace -efile ghci doesn't show anything weird, except maybe:
stat64(./Prelude.hs, 0xbfffcfe0)  = -1 ENOENT (No such file or directory)
stat64(./Prelude.lhs, 0xbfffcfe0) = -1 ENOENT (No such file or directory)
stat64(./Prelude.hi-boot-5, 0xbfffcfe0) = -1 ENOENT (No such file or directory)
stat64(./Prelude.hi-boot, 0xbfffcfe0) = -1 ENOENT (No such file or directory)


I wanted to have a look at the code to find out what's wrong, but i can't find
the time :-(

ghci is built using http://people.mandrakesoft.com/~prigaux/ghc.spec where
%configure is ./configure i586-mandrake-linux-gnu --prefix=/usr --exec-prefix=/usr 
--bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share 
--includedir=/usr/include --libdir=/usr/lib --libexecdir=/usr/lib 
--localstatedir=/var/lib --sharedstatedir=/usr/com --mandir=/usr/share/man 
--infodir=/usr/share/info

Any idea what's wrong?


Thanks

--
Pixel
programming languages addict  http://merd.net/pixel/language-study/

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



Re: ghci panic (unknown symbol stg_gc_l1)

2002-01-26 Thread Pixel

Sigbjorn Finne [EMAIL PROTECTED] writes:

 GHCi doesn't load the RTS package (nor GMP),
 as they're both baked into the binary. My guess is that
 you've built ghci using 5.02.1; you need to use 5.02.2
 (i.e., do two stage build.)  The missing symbol was
 introduced in 5.02.2's RTS.

cool, rebuilding :)

thanks!

PS: maybe some kind of warning could be added for this case?

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



Re: Having contraints like 'Fractional Int = IO ()'

2001-11-13 Thread Pixel

Jesper Louis Andersen [EMAIL PROTECTED] writes:

 This problem has had my attention for a while now. I hope someone would
 like to help me out on the problem.
 
 I have a simple average function defined as:
 
 mean:: (Fractional a) = [a] - a
 mean l  = (sum l)/ fromIntegral (length l)

due to the absence of subtyping, things like this will work only if you don't
precise the type, keeping class constraints.

-- length2 :: Num a = [b] - a
length2 [] = 0
length2 (x:xs) = 1 + length2 xs

-- mean :: Fractional a = [a] - a
mean l = sum l / length2 l

m = (mean [1,0,0] :: Rational, mean [1,0,0] :: Double)

gives 1%3 and 0.33


(thanks to pad for pinpointing the haskell solution, 
 merd solution is http://merd.sf.net/inference.txt)

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: independant monads used together?

2001-11-10 Thread Pixel

Jan-Willem Maessen [EMAIL PROTECTED] writes:

 Pixel [EMAIL PROTECTED] asks:
  I'm trying to achieve something like (ocaml)
[code deleted]
  which is a foldl on 2 iterators. I've managed to use monads for one iterator,
  but i completly miss the way to work with 2 monads. Is there really no other
  solution than creating a monad over the 2 iterators??
 
 Why monadic iterators at all?  One of the great things about lazy
 lists is they encapsulate iteration nicely:  Elements can be generated
 as they're consumed. 

oops, i forgot this. /me was trying to translate from a language to another
without thinking :-(

of course, an iterator over a structure is a to_list function. /me bad

[...]

 You're having trouble combining the results of two state monads
 precisely because they're manipulating two *independent* pieces of
 state, and you're trying to combine the *states* of the monads in some
 fashion.  What should the type of the result of the manipulation be?
 Where are the initial states of each computation coming from?

I don't quite understand those questions. Combining states is a common task in
imperative world.

I must be missing something. I still don't understand what is to be done to
mix monads. As far as I've seen the only really used monad is IO. So I can't
find useful examples using the standard library.
But suppose I have GUI which interacts via the gui and has getLine' and
print', how can i do something that:

- getLine on IO, getLine' on GUI
- verify it is the same
- print on IO, print' on GUI
- ...
 
 Some computations really are much more easily done in the value domain
 then under a wrapper like a monad which obscures their real structure.

Well, the intention was to hide the real structure :)
But i agree i missed something simple...


thanks, Pixel.

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



independant monads used together?

2001-11-09 Thread Pixel

I'm trying to achieve something like (ocaml)

let rec zipfold f init it1 it2 =
  if it1#is_end || it2#is_end then init
  else 
let v1, v2 = it1#value, it2#value in
it1#next ; it2#next ;
zipfold f (f v1 v2 init) it1 it2

which is a foldl on 2 iterators. I've managed to use monads for one iterator,
but i completly miss the way to work with 2 monads. Is there really no other
solution than creating a monad over the 2 iterators??


-- using the StateTrans as in http://www.engr.mun.ca/~theo/Misc/haskell_and_monads.htm
newtype StateTrans s a = ST( s - (s, a) )

-- can't write l == [] otherwise it need Eq on elem of lists
is_empty_list [] = True
is_empty_list _ = False

is_empty = ST(\l- (l, is_empty_list l))
val = ST(\l - (l, head l))
next = ST(\l - (tail l, ()))

myfoldl f init =
do b - is_empty
   if b
  then return init
  else do e - val
  next
  myfoldl f (f e init)


thanks

--
Pixel

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: Multi-parameter OOP

2001-10-28 Thread Pixel

Richard Uhtenwoldt [EMAIL PROTECTED] writes:

[...]

 My reason for posting is to
 bring attention to how something similar is done in the language merd,
 whose designer posts here under the name pixel, and which
 is actually implemented I think.

not really. still coding... :)

[...]

 http://merd.sourceforge.net/types.png

Was in too small resolution, fixed. 
Try http://merd.sourceforge.net/types.pdf for nicer display.

 In addition, merd has a type called a struct, written a || b.
 For reasons I do not understand, instead of defining, eg,
 
 point = (double,double)
 
 or 
 
 point = (Point,double,double)
 
 pixel prefers to define
 
 point   = (X,double) || (Y,double)

The reason is tuples do not have any subtyping relationship (unless you add
it, but it gets ugly ;p)
(it also enforces that record fields are not ordered)


The || is defined elsewhere[1] as /\  aka the intersection type operator
(maybe i should rename it, || is ugly, /\ is not bad...)

It is generally used as a record subtyping operator.
It is also used for ad'hoc overloading:

  show !! String - String || Int - String  [2]

but in fact, it can be useful in many areas, if you allow || to work on
values:

  default_val = 0 || []

  [ 1, foo ].map(x - x + 1||bar)
 #= [ 2, foobar ]

- type of [ 1, foo ] is List(1 | foo)
(just like type of [ True, False ] is List(Bool) where Bool = True | False)
- (x - x + 1||bar) is alike (x - x + 1) || (x - x + bar)
so the type is Int-Int || String-String [3]
- the result is of type List(String | Int)  [4]

for pattern matching:

  (\s+):(\d+)  returns String, String||Int  allowing the use with no cast
 as an Int and/or as a String
  

[1] Intersection Types and Bounded Polymorphism http://citeseer.nj.nec.com/54630.html
[2] can be factorised as show !! String|Int - String
[3] well in fact + !! o,o - o  where o ! Addable
so the type is x - x where 1||bar ! x ! Addable 
   which gives x - x where x ! String|Int  
 when going to the closed world
 where + is defined for types Int and String
[4] hum, in fact merd evaluates what it can at compile time, so the type is
the type of [ 2, foobar ] which is List(2 | foobar)
--
Pixel

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: Enum class

2001-10-23 Thread Pixel

George Russell [EMAIL PROTECTED] writes:

   (1) succ  pred.  These appear for float to correspond to adding or subtracting
   1.0.  (I am finding this out by testing with ghci; it's not specified where
   it should be, in section 6.3.4 of the standard).   Because of rounding errors,
   succ and pred fail many of the properties for float they have for integers, EG
  succ . pred = pred . succ = id
  succ x  x
   and so on.

Quite a few pbs with overflow on Int too:

i :: Int
i = 0x7fff

i_plus_1 = i+1
  -- ghc : -2147483648
  -- hugs: -2147483648

i_succ = succ i
  -- ghc : *** Exception: Prelude.Enum.succ{Int}: tried to take `succ' of maxBound
  -- hugs: -2147483648

j :: Int
j = 0x8000
  -- ghc : -2147483648
  -- hugs: Program error: {primIntegerToInt 2147483648}

k :: Int
k = 0x1
  -- ghc : 0
  -- hugs: Program error: {primIntegerToInt 4294967296}

i':: Integer
i'= 0x7fff
i_plus_1' = i+1
  -- ghc : 2147483648
  -- hugs: 2147483648

i_succ' = succ i'
  -- ghc : 2147483648
  -- hugs: -2147483648

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: readFile close behaviour

2001-10-05 Thread Pixel

Jens Petersen [EMAIL PROTECTED] writes:

 % ./manyfiles 
 
 Fail: resource exhausted
 Action: openFile
 Reason: process file table full
 File: manyfiles.hs

It works here on 5.02


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



Re: readFile close behaviour

2001-10-05 Thread Pixel

Malcolm Wallace [EMAIL PROTECTED] writes:

 It is really a question of when the garbage collector runs.
 Your example program is very small, so the GC does not run (and
 therefore does not collect the unused handles) before the open file
 table is filled.

what about running the garbage collector for such errors, just in case it can
help? all resources that can be freed by the garbage collector should trigger
a GC when that resource is low, uh? (maybe that's what ghc-5.02 is doing since
i've not been able to reproduce the pb after increasing the heap)

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



Re: The future of Haskell discussion

2001-09-15 Thread Pixel

Marcin 'Qrczak' Kowalczyk [EMAIL PROTECTED] writes:

 Fri, 14 Sep 2001 02:09:21 -0700, Julian Seward (Intl Vendor) 
[EMAIL PROTECTED] pisze:
 
  The lack of any way to interface to C++ is a problem, IMO.
  I would love to be able to write Haskell programs using Qt
  and ultimately the KDE libraries, both of which are C++, but
  I can't, at the mo.
 
 I think it should be easy to add support for C++, except exceptions.

for info, Qt/KDE do not use exceptions and compile with -fno-exceptions

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: GHC Mandrake problem

2001-08-24 Thread Pixel

Hampus Ram [EMAIL PROTECTED] writes:

  Loading package std ... ghc-5.00.2: can't find .o or .so/.DLL for: m (lib.so: 
cannot open shared object file: No such file or directory)
 
  Can anyone tell me what's missing, or how to fix this??
 
 A _very_ ugly fix for this problem is to make a symbolic link to
 libm.so and call it lib.so.

Maybe a nicer fix:



--- ghc-5.00.2/ghc/driver/PackageSrc.hs.pix	Mon Apr 30 18:25:32 2001
+++ ghc-5.00.2/ghc/driver/PackageSrc.hs	Fri Aug 24 13:10:32 2001
@@ -127,7 +127,7 @@
 #   ifdef mingw32_TARGET_OS
 [wsock32, msvcrt]
 #   else
-[m]   -- libm, that is
+[]   -- libm, that is
 #   endif
 ,
 include_dirs   = if installing



Re: problem with installing ghc-5.00 from .hc file

2001-04-16 Thread Pixel

Saswat Anand [EMAIL PROTECTED] writes:

 I am trying to install ghc-5.00 from .hc files on windows NT. But I get the
 following error. It seems Package.hc is missing.
 Please help.

i'm having pb too:

- something is missing for Readline support

 ../../ghc/utils/hsc2hs/hsc2hs-inplace Readline.hsc
 make: ../../ghc/utils/hsc2hs/hsc2hs-inplace: Command not found

 pixel@no:~/rpm/BUILD/ghc-5.00/hslibs/utills Readline*
 Readline.hc  Readline.hsc  Readline_stub.c  Readline_stub.h  Readline_stub.o

- file Directory_hsc.h and Time_hsc.h are missing

 pixel@no:~/rpm/BUILD/ghc-5.00/ghc/lib/stdmake all
 [...]
 gcc -x c Directory.hc -o Directory.raw_s -S -O  -fno-defer-pop -fomit-frame-pointer  
-D__GLASGOW_HASKELL__=411 -O -I/home/pixel/rpm/BUILD/ghc-5.00/ghc/includes 
-I/home/pixel/rpm/BUILD/ghc-5.00/ghc/lib/std/cbits 
-I/home/pixel/rpm/BUILD/ghc-5.00/hslibs/lang/cbits 
-I/home/pixel/rpm/BUILD/ghc-5.00/hslibs/posix/cbits 
-I/home/pixel/rpm/BUILD/ghc-5.00/hslibs/util/cbits 
-I/home/pixel/rpm/BUILD/ghc-5.00/hslibs/text/cbits 
-I/home/pixel/rpm/BUILD/ghc-5.00/hslibs/hssource/cbits-I.  `echo  | sed 
's/^$/-DSTOLEN_X86_REGS=4/'`
 Directory.hc:3:27: Directory_hsc.h: No such file or directory

% grep '#include' Directory.hsc  Directory_hsc.h

and something alike for Time_hsc.h from Time.hsc

makes it compile, but s_ISDIR is not defined afterwards, so no real solution.

- skipping directory 'driver' (is that nonsense?) and trying to make directly
'compiler' (after building ghc/lib and ghc/rts)

basicTypes/DataCon.o: In function `s720_1_alt':
basicTypes/DataCon.o(.text+0x299f): undefined reference to `PrelList_zdwlvl_fast3'
[...]
basicTypes/DataCon.o(.text+0x2c3c): more undefined references to 
`PrelList_zdwlvl_fast3' follow
prelude/PrelRules.o: In function `sbfp_ret':
prelude/PrelRules.o(.text+0x33c7): undefined reference to `PrelWord_zdwa6_fast1'
[...]
prelude/PrelRules.o(.text+0x8940): more undefined references to `PrelWord_zdwa6_fast1' 
follow
simplCore/Simplify.o: In function `sf73_1_alt':
simplCore/Simplify.o(.text+0x2456): undefined reference to `PrelList_zdwlvl_fast3'
absCSyn/PprAbsC.o: In function `sjtR_fast3':
absCSyn/PprAbsC.o(.text+0x18177): undefined reference to `PrelList_zdwlvl_fast3'
ghci/InteractiveUI.o: In function `__init_InteractiveUI':
ghci/InteractiveUI.o(.text+0xba): undefined reference to `__init_Readline'
ghci/InteractiveUI.o: In function `sjW4_srt':
ghci/InteractiveUI.o(.text+0xb6ec): undefined reference to 
`Readline_zdwreadline_closure'
ghci/InteractiveUI.o: In function `skLW_dflt':
ghci/InteractiveUI.o(.text+0xb876): undefined reference to 
`Readline_addzuhistory_closure'
ghci/InteractiveUI.o: In function `skLz_dflt':
ghci/InteractiveUI.o(.text+0xb954): undefined reference to `Readline_zdwreadline_fast2'
/home/pixel/rpm/BUILD/ghc-5.00/ghc/lib/std/libHSstd.a(Directory.o): In function 
`s8KQ_entry':
Directory.o(.text+0x38c): undefined reference to `s_ISDIR'
[...]
collect2: ld returned 1 exit status


Please help, cu Pixel.

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



compiling ghc-5 with x86 HC files

2001-04-15 Thread Pixel

I've found the "x86 HC files, for building from source without a previous
installation of GHC" which seemed promising. Alas i don't know what to do with
it. I tried untaring it together with the source:

pixel@no:~/rpm/SPECSrpm -bp ghc.spec
Executing(%prep): /bin/sh -e /home/pixel/rpm/tmp/rpm-tmp.84335
[...]
+ cd /home/pixel/rpm/BUILD
+ rm -rf ghc-5.00
+ /usr/bin/bzip2 -dc /home/pixel/rpm/SOURCES/ghc-5.00-src.tar.bz2
+ tar -xf -
[...]
+ cd /home/pixel/rpm/BUILD
+ /usr/bin/bzip2 -dc /home/pixel/rpm/SOURCES/ghc-5.00-i386-hc.tar.bz2
+ tar -xf -
[...]

pixel@no:~/rpm/BUILD/ghc-5.00autoconf
configure.in:733: warning: AC_TRY_RUN called without default to allow cross compiling
configure.in:914: warning: AC_TRY_RUN called without default to allow cross compiling
(fptools configure script wizard sez: "don't worry, the above warning is harmless (to 
us.)")
pixel@no:~/rpm/BUILD/ghc-5.00(cd ghc ; autoconf)
pixel@no:~/rpm/BUILD/ghc-5.00./configure /tmp/configure.output
pixel@no:~/rpm/BUILD/ghc-5.00make /tmp/log 21

configure seems ok (i did install happy 1.9 otherwise configure was not happy),
but "make" is going crazy with things like:

==fptools== make boot -wr;
 in /home/pixel/rpm/BUILD/ghc-5.00/glafp-utils/lndir

../../glafp-utils/mkdependC/mkdependC -f .depend -- -O -- lndir.c 
# 46 "lndir.c"
# 1 "lndir-Xos.h" 1
# 27 "lndir-Xos.h"
[...]

which just seems to output the file preprocessed?

==fptools== make boot - --no-print-directory -r;
 in /home/pixel/rpm/BUILD/ghc-5.00/ghc/utils/ghc-pkg

M -optdep-f -optdep.depend  -osuf o-ldl -cpp -DPKG_TOOL -DWANT_PRETTY -package 
lang -package util -package textMain.hs Package.hs
make[3]: M: Command not found
make[3]: [depend] Error 127 (ignored)


I've not tried a lot yet, but some help would be nice :)


Thanks, cu Pixel.


files:
  ftp://ftp.mandrakesoft.com/pub/pixel/configure.output
  ftp://ftp.mandrakesoft.com/pub/pixel/log.bz2

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



Re: Union Types for Haskell!?

2000-11-24 Thread Pixel

Fergus Henderson [EMAIL PROTECTED] writes:

[...]
   (2) Allow pattern matching on values of particular types,
   using `case'.
[...]
 If we allow (2), then some programming mistakes that previously
 were type errors would instead become just inexhaustive pattern
 matches for which you get a run-time error.
 
 For example:
 
   foo :: Maybe a - b - Maybe b
   foo x y = case list of
   [] - Nothing
   (x:xs) - Just x
   where list = case x of
   Nothing - 0-- oops, meant [] instead of 0
   Just foo - [y]
   
 If union types were allowed, with (2) above, this example would be
 legal, with `list' having the union type { [a], Integer }.

if you disallow undeclared union types, you'll catch easily this kind of errors.

 But `foo Nothing 42' would evaluate to bottom, since the `case list'
 expression has no case with a pattern of type Integer.
 
 So allowing union types in this way would reduce static type safety,
 at least unless we also forbid inexhaustive pattern matches.

well allowing inexhaustive pattern matching always leads to less type
safetyness, no news :)

And of course subtyping also reduce type safetyness. 
But it is the same for type classes. No one is more safe than using '+' for
integers and '+.' for floats...

 
 If instead you only allow (1), then probably union types would
 not be suitable for expressing the kinds of things that you want
 to express with them.

sure, you don't win anything.

 
  Is there any reason for this restriction
  in the Haskell type system? Does this lead to losing the principal type
  property?
 
 If you allow (2) above, there may be serious problems for
 principal types.  For example, consider
 
   f x = case x of
   Nothing - False
   Just _ - True
 
 What's the most general type for `f'?
 The type `f :: Maybe a - Bool' is less general than
 e.g. `f :: Union { Maybe a, ... } - Bool',
 but you certainly don't want to infer the latter type.

not necessarily. 
If you disallow undeclared union types, the only occurence of Union { Maybe a,
... } will be Maybe a, unless one really wants to extend Maybe...


cu Pixel.

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell



Re: ghc-4.06-1.src.rpm

2000-03-25 Thread Pixel

Peter Hancock [EMAIL PROTECTED] writes:

 It would be great if at least one haskell system could get into the
 standard linux distributions.

As for linux-mandrake, i take care of including ``exotic'' languages, 
(aka nice languages :)

This includes ghc and hugs98 (and also mercury, ocaml)


cu Pixel.