Re: [Haskell-cafe] Existential question

2011-08-19 Thread Ryan Ingram
On Wed, Aug 17, 2011 at 4:49 PM, Tom Schouten t...@zwizwa.be wrote:

 {-# LANGUAGE ExistentialQuantification #-}

 -- Dear Cafe, this one works.
 data Kl' s i o = Kl' (i - s - (s, o))
 iso' :: (i - Kl' s () o) - Kl' s i o
 iso' f = Kl' $ \i s - (\(Kl' kl') - kl' () s) (f i)

 -- Is there a way to make this one work also?
 data Kl i o = forall s. Kl (i - s - (s, o))
 iso :: (i - Kl () o) - Kl i o
 iso f = Kl $ \i s - (\(Kl kl) - kl () s) (f i)


Not without moving the quantifier, as Oleg says.  Here is why:

Existential types are equivalent to packing up a type with the constructor;
imagine KI as

data KI i o = KI @s (i - s - (s,o))   -- not legal haskell

where @s represents hold a type s which can be used in the other elements
of the structure.  An example element of this type:

  KI @[Int] (\i s - (i:s, sum s)) :: KI Int Int

Trying to implement iso as you suggest, we end up with

iso f = KI ?? (\i s - case f i of ...)

What do we put in the ??.  In fact, it's not possible to find a solution;
consider this:

ki1 :: KI () Int
ki1 = KI @Int (\() s - (s+1, s))

ki2 :: KI () Int
ki2 = KI @() (\() () - ((), 0))

f :: Bool - KI () Int
f x = if x then ki1 else ki2

iso f = KI ?? ??

The problem is that we have multiple possible internal state types!

  -- ryan


 {-
Couldn't match type `s0' with `s'
  because type variable `s' would escape its scope
This (rigid, skolem) type variable is bound by
  a pattern with constructor
Kl :: forall i o s. (i - s - (s, o)) - Kl i o,
  in a lambda abstraction
The following variables have types that mention s0
  s :: s0 (bound at /home/tom/meta/haskell/iso.hs:**11:17)
In the pattern: Kl kl
In the expression: \ (Kl kl) - kl () s
In the expression: (\ (Kl kl) - kl () s) (f i)
 -}


 __**_
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/**mailman/listinfo/haskell-cafehttp://www.haskell.org/mailman/listinfo/haskell-cafe

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


[Haskell-cafe] Simon PJ in Australia

2011-08-19 Thread Simon Peyton-Jones
This is a message for Australian FPers -- sorry to spam the rest of you.

I'm crossing the planet to Australia for YOW (Melbourne Dec 1-2, Brisbane Dec 
5-6).  http://www.yowconference.com.au/YOW2011/

I'm committed for the conference dates of course, but I could spend a few days 
before or afterwards, hanging out with some of you guys.  Hack on GHC, give a 
talk, eat pizza, university departments, Haskell users groups, surfing (on 
water, that is)

Do drop me (not the list) a line if any of that sounds fun.

Simon

PS: John Hughes is coming to Yow too, so you could try luring him into your 
lair too.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Simon PJ in Australia

2011-08-19 Thread Tony Morris
On 08/19/2011 05:56 PM, Simon Peyton-Jones wrote:

 This is a message for *Australian FPers* -- sorry to spam the rest of you.

  

 I'm crossing the planet to Australia for YOW (Melbourne Dec 1-2,
 Brisbane Dec 5-6).  http://www.yowconference.com.au/YOW2011/

  

 I'm committed for the conference dates of course, but I could spend a
 few days before or afterwards, hanging out with some of you guys. 
 Hack on GHC, give a talk, eat pizza, university departments, Haskell
 users groups, surfing (on water, that is)

  

 Do drop me (not the list) a line if any of that sounds fun.

  

 Simon

  

 PS: John Hughes is coming to Yow too, so you could try luring him into
 your lair too.


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

...and I will be running a Haskell/FP workshop. I'm as keen as Simon to
meet others from further afield with similar interests.
http://www.yowconference.com.au/YOW2011/general/workshopDetails.html?eventId=3552

PS: we have a significant FP community here in Brisbane with nearly 250
members http://bfpg.org/

-- 
Tony Morris
http://tmorris.net/


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


Re: [Haskell-cafe] custom SQL-to-Haskell type conversion in HDBC

2011-08-19 Thread Erik Hesselink
On Fri, Aug 19, 2011 at 07:23, Henry House hajho...@hajhouse.org wrote:
 Does there exist any sample code or other resources on writing a custom
 SQL-to-Haskell datatype converter instance for use with HDBC that would be
 accessible to someone just starting with Haskell? The reason I need this is
 because of this problem (using PostgreSQL):

 Prelude Database.HDBC.PostgreSQL Database.HDBC res - (quickQuery db select 
 1::numeric(5,4); [])
 Prelude Database.HDBC.PostgreSQL Database.HDBC res
 [[SqlRational (1 % 1)]]
 Prelude Database.HDBC.PostgreSQL Database.HDBC res - (quickQuery db select 
 1::numeric(5,0); [])
 [[SqlRational (1 % 1)]]

 where db is a database connection. The SQL values 1::numeric(5,4) and
 1::numeric(5,0) are supposed to be fixed-precision numbers having 4 and zero
 significant decimal figures after the decimal point, respectively. Both are
 offered by HDBC as the same SqlValue, SqlRational (1 % 1) but they are not
 really the same at all. The precision information has been lost. The native
 outputs of PostgreSQL, before HDBC's type conversion, are 1. and 1 for
 'select 1::numeric(5,4);' and 'select 1::numeric(5,0);', respectively.

Do you really need the precision info about the column, or do you just
need the values at the right precision? Because you get the last thing
already:

Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio
Control.Monad (fromSql . head . head) `liftM` (quickQuery db select
1.231 ::numeric(5,0); []) :: IO Rational
1 % 1
Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio
Control.Monad (fromSql . head . head) `liftM` (quickQuery db select
1.231 ::numeric(5,4); []) :: IO Rational
1231 % 1000

If you need the precision information, perhaps 'describeResult' will
give you what you need. I've never used it, but it looks like it
might.

Erik

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


Re: [Haskell-cafe] Simon PJ in Australia

2011-08-19 Thread Arlen Cuss
You heard it here first; Simon's down here in Aus to eat pizza,
university departments, Haskell users groups. Will he leave nothing left!?

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


[Haskell-cafe] Problem with types

2011-08-19 Thread Anupam Jain
Hi all,

Suppose I have a compound data type -

data M o = M (String,o)

Now, I can define a function that works for ALL M irrespective of o. For
example -

f :: M o - M o
f (M (s,o)) = M (s++!, o)

I can also use this function in an expression, applying it to different
types without problem -

p = (m1',m2') where
  m1 = M (1, ())
  m2 = M (2, True)
  m1' = f m1
  m2' = f m2

Main* p
(M (1!,()),M (2!,True))

However, if I try to parameterise over the function 'f' it does not work!  -

p f = (m1',m2') where
  m1 = M (1, ())
  m2 = M (2, True)
  m1' = f m1
  m2' = f m2

It doesn't even typecheck, producing the error - Couldn't match expected
type 'Bool' with actual type '()'

Is there a particular reason for this? How can I define a function like 'p'
within Haskell?

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


Re: [Haskell-cafe] Problem with types

2011-08-19 Thread MigMit
p :: (forall o. M o - M o) - ...

Отправлено с iPad

19.08.2011, в 16:06, Anupam Jain ajn...@gmail.com написал(а):

 Hi all,
 
 Suppose I have a compound data type -
 
 data M o = M (String,o)
 
 Now, I can define a function that works for ALL M irrespective of o. For 
 example -
 
 f :: M o - M o
 f (M (s,o)) = M (s++!, o)
 
 I can also use this function in an expression, applying it to different types 
 without problem -
 
 p = (m1',m2') where
   m1 = M (1, ())
   m2 = M (2, True)
   m1' = f m1
   m2' = f m2
 
 Main* p
 (M (1!,()),M (2!,True))
 
 However, if I try to parameterise over the function 'f' it does not work!  -
 
 p f = (m1',m2') where
   m1 = M (1, ())
   m2 = M (2, True)
   m1' = f m1
   m2' = f m2
 
 It doesn't even typecheck, producing the error - Couldn't match expected 
 type 'Bool' with actual type '()'
 
 Is there a particular reason for this? How can I define a function like 'p' 
 within Haskell?
 
 Thanks,
 Anupam Jain
 ___
 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] Problem with types

2011-08-19 Thread Erik Hesselink
On Fri, Aug 19, 2011 at 14:06, Anupam Jain ajn...@gmail.com wrote:
 Hi all,
 Suppose I have a compound data type -
 data M o = M (String,o)
 Now, I can define a function that works for ALL M irrespective of o. For
 example -
 f :: M o - M o
 f (M (s,o)) = M (s++!, o)
 I can also use this function in an expression, applying it to different
 types without problem -
 p = (m1',m2') where
   m1 = M (1, ())
   m2 = M (2, True)
   m1' = f m1
   m2' = f m2
 Main* p
 (M (1!,()),M (2!,True))
 However, if I try to parameterise over the function 'f' it does not work!  -
 p f = (m1',m2') where
   m1 = M (1, ())
   m2 = M (2, True)
   m1' = f m1
   m2' = f m2
 It doesn't even typecheck, producing the error - Couldn't match expected
 type 'Bool' with actual type '()'
 Is there a particular reason for this? How can I define a function like 'p'
 within Haskell?

If you write down the type for 'p', you get something like this:

p :: (forall a. M a - M a) - (M b, M b)

That is, the type variable 'a' isn't top level, but is forall'ed in
the function you pass. This is called a rank 2 type, and it cannot be
inferred automatically by GHC. You have to specify it yourself, and
turn on the Rank2Types or RankNTypes extension.

Erik

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


Re: [Haskell-cafe] Problem with types

2011-08-19 Thread Ertugrul Soeylemez
Anupam Jain ajn...@gmail.com wrote:

 However, if I try to parameterise over the function 'f' it does not
 work!  -

 p f = (m1',m2') where
   m1 = M (1, ())
   m2 = M (2, True)
   m1' = f m1
   m2' = f m2

 It doesn't even typecheck, producing the error - Couldn't match
 expected type 'Bool' with actual type '()'

 Is there a particular reason for this? How can I define a function
 like 'p' within Haskell?

Try to write the type signature for 'p'.

And as a general advice:  Always write type signatures.


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife = sex)
http://ertes.de/



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


Re: [Haskell-cafe] Failed link to mixed-language shared object.

2011-08-19 Thread David Banas
On Thu, 2011-08-18 at 20:32 -0700, David Banas wrote:
 Hi all,
 
 Does this trigger recollection in anyone:
 
 dbanas@dbanas-eeepc:~/prj/haskell/AMIParse/trunk$ make
 ghc -dynamic -o ami_test -L. -lami ami_test.o
 ./libami.so: undefined reference to `__stginit_haskell98_MarshalArray_'
 ./libami.so: undefined reference to `__stginit_haskell98_MarshalError_'
 collect2: ld returned 1 exit status
 make: *** [ami_test] Error 1
 dbanas@dbanas-eeepc:~/prj/haskell/AMIParse/trunk$ 
 
 ?
 Know what I need to do?
 
 Thanks,
 -db
 

So, I was able to make my link errors go away, by adding `-shared' to my
command line:

dbanas@dbanas-eeepc:~/prj/haskell/AMIParse/trunk$ make
ghc -no-hs-main -shared -dynamic -o ami_test -L. -lami ami_test.o

However, when I try to execute the resultant program, I get a
segmentation fault:

dbanas@dbanas-eeepc:~/prj/haskell/AMIParse/trunk$ ./ami_test test.ami 
Segmentation fault

Tracing this shows that the `main' pointer of the program appears to be
NULL:

dbanas@dbanas-eeepc:~/prj/haskell/AMIParse/trunk$ gdb --args ./ami_test
test.ami 
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type show
copying
and show warranty for details.
This GDB was configured as i486-linux-gnu.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/...
Reading symbols
from /home/dbanas/prj/haskell/AMIParse/trunk/ami_test...done.
(gdb) l
2   #include stdlib.h
3   #include string.h
4   //#include HsFFI.h
5   #include ami_model.h
6   
7   #define DEF_AMI_FILE test.ami
8   #define VEC_SIZE   8
9   #define MAX_LINE_LEN 256
10  
11  int main(int argc, char *argv[]) {
(gdb) b 11
Breakpoint 1 at 0x87d: file ami_test.c, line 11.
(gdb) run
Starting program: /home/dbanas/prj/haskell/AMIParse/trunk/ami_test
test.ami

Program received signal SIGSEGV, Segmentation fault.
0x0002 in ?? ()

I assume that's because of the `-shared' flag.

Any thoughts?

Thanks,
-db



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


Re: [Haskell-cafe] custom SQL-to-Haskell type conversion in HDBC

2011-08-19 Thread Henry House
On Friday, 19 August 2011, Erik Hesselink wrote:
 Do you really need the precision info about the column, or do you just
 need the values at the right precision? Because you get the last thing
 already:
 
 Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio
 Control.Monad (fromSql . head . head) `liftM` (quickQuery db select
 1.231 ::numeric(5,0); []) :: IO Rational
 1 % 1
 Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio
 Control.Monad (fromSql . head . head) `liftM` (quickQuery db select
 1.231 ::numeric(5,4); []) :: IO Rational
 1231 % 1000

I'm not sure I understand the distinction --- to my way of thinking,
getting the value at the right precision means getting the correct
number of significant decimal digits, which both your example and mine
fail to provide.

Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio Control.Monad
(fromSql . head . head) `liftM`
   (quickQuery db select 1.231 ::numeric(10,4); []) :: IO Rational
-- gives 1231 % 1000 == 1.231 in decimal notation
Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio Control.Monad
(fromSql . head . head) `liftM`
   (quickQuery db select 1.231 ::numeric(10,8); []) :: IO Rational
-- still gives 1231 % 1000 but should be 1.2131 in decimal notation
-- or 1231000 % 100 in rational notation

 If you need the precision information, perhaps 'describeResult' will
 give you what you need. I've never used it, but it looks like it
 might.

Thanks for the suggestion. That will work, but ideally i'd like to have
the normal usage of quickQuery, etc return correct data. Unless I am
missing something here, the method of getting precision information
using describeResult would be to fetch the result set, then find any
columns having a numeric(x,y) SQL type and transform them. Even just
getting the raw string response from the RDBMS would be better than that
since the raw response is actually already a correctly formatted string
representation of the data so I could use it for output without any
further transformation.

Is there a way to get raw response data from the RDBMS through HDBC?

-- 
Henry House
+1 530 848-1238

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


Re: [Haskell-cafe] custom SQL-to-Haskell type conversion in HDBC

2011-08-19 Thread Erik Hesselink
On Fri, Aug 19, 2011 at 16:09, Henry House hajho...@hajhouse.org wrote:
 On Friday, 19 August 2011, Erik Hesselink wrote:
 Do you really need the precision info about the column, or do you just
 need the values at the right precision? Because you get the last thing
 already:

 Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio
 Control.Monad (fromSql . head . head) `liftM` (quickQuery db select
 1.231 ::numeric(5,0); []) :: IO Rational
 1 % 1
 Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio
 Control.Monad (fromSql . head . head) `liftM` (quickQuery db select
 1.231 ::numeric(5,4); []) :: IO Rational
 1231 % 1000

 I'm not sure I understand the distinction --- to my way of thinking,
 getting the value at the right precision means getting the correct
 number of significant decimal digits, which both your example and mine
 fail to provide.

 Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio Control.Monad
 (fromSql . head . head) `liftM`
   (quickQuery db select 1.231 ::numeric(10,4); []) :: IO Rational
 -- gives 1231 % 1000 == 1.231 in decimal notation
 Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio Control.Monad
 (fromSql . head . head) `liftM`
   (quickQuery db select 1.231 ::numeric(10,8); []) :: IO Rational
 -- still gives 1231 % 1000 but should be 1.2131 in decimal notation
 -- or 1231000 % 100 in rational notation

The % notation is a rational, so 'infinite' precision. So '1 % 1' and
'1000 % 1000' are exactly the same, semantically. It's like fractions
instead of decimal digits.

Why exactly do you need the precision information?

Erik

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


Re: [Haskell-cafe] custom SQL-to-Haskell type conversion in HDBC

2011-08-19 Thread Brandon Allbery
On Fri, Aug 19, 2011 at 10:09, Henry House hajho...@hajhouse.org wrote:

 I'm not sure I understand the distinction --- to my way of thinking,
 getting the value at the right precision means getting the correct
 number of significant decimal digits, which both your example and mine
 fail to provide.


So you want display format data instead of something that you can do
computations with?  HDBC is giving you the latter; the precision is correct
for computation, although it could be argued that a Fixed type would be
better if you intend to propagate exact precision through operations.  (That
said, I believe Fixed obeys exact mathematical precision instead of
replicating your SQL backend's limitations, so you'd be unhappy again in
case of multiplication or division.)

I would suggest that if you want SQL formatted string output, you describe
that in the query instead of expecting HDBC to convert numeric data to
string while duplicating your SQL backend's formatting.  Otherwise, perhaps
you'd be better suited to a language with a looser type system, so you can
pretend string and numeric values are the same thing and usually get
something resembling the right result.

-- 
brandon s allbery  allber...@gmail.com
wandering unix systems administrator (available) (412) 475-9364 vm/sms
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] custom SQL-to-Haskell type conversion in HDBC

2011-08-19 Thread Henry House
On Friday, 19 August 2011, Erik Hesselink wrote:
 On Fri, Aug 19, 2011 at 16:09, Henry House hajho...@hajhouse.org wrote:
  On Friday, 19 August 2011, Erik Hesselink wrote:
  Do you really need the precision info about the column, or do you just
  need the values at the right precision? Because you get the last thing
  already:
 
  Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio
  Control.Monad (fromSql . head . head) `liftM` (quickQuery db select
  1.231 ::numeric(5,0); []) :: IO Rational
  1 % 1
  Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio
  Control.Monad (fromSql . head . head) `liftM` (quickQuery db select
  1.231 ::numeric(5,4); []) :: IO Rational
  1231 % 1000
 
  I'm not sure I understand the distinction --- to my way of thinking,
  getting the value at the right precision means getting the correct
  number of significant decimal digits, which both your example and mine
  fail to provide.
 
  Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio Control.Monad
  (fromSql . head . head) `liftM`
    (quickQuery db select 1.231 ::numeric(10,4); []) :: IO Rational
  -- gives 1231 % 1000 == 1.231 in decimal notation
  Prelude Database.HDBC.PostgreSQL Database.HDBC Data.Ratio Control.Monad
  (fromSql . head . head) `liftM`
    (quickQuery db select 1.231 ::numeric(10,8); []) :: IO Rational
  -- still gives 1231 % 1000 but should be 1.2131 in decimal notation
  -- or 1231000 % 100 in rational notation
 
 The % notation is a rational, so 'infinite' precision. So '1 % 1' and
 '1000 % 1000' are exactly the same, semantically. It's like fractions
 instead of decimal digits.

You're right, of course. My example was something of an abuse of
notation to include a notion of precision where it is actually an
incompatible concept.

 Why exactly do you need the precision information?

Empirical measurements (e.g., sizes of some fields in hectares) are
precise only to a certain level of measurement error. Thus, the area
measurements 1 ha and 1.000 ha are not equivalent or interchangeable.
Database engines recognize this fact by providing different data types
for rational numbers and fixed-precision decimal numbers.

The bottom line for me is that the conversion of a fixed-precision
decimal number as a rational is both throwing away information (the
precision) as well as introducing bogus information (the notion that the
result value has greater --- i.e., infinite --- precision that was in
fact intended when that value was stored).

-- 
Henry House
+1 530 848-1238

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


Re: [Haskell-cafe] custom SQL-to-Haskell type conversion in HDBC

2011-08-19 Thread Erik Hesselink
On Fri, Aug 19, 2011 at 16:53, Henry House hajho...@hajhouse.org wrote:
 On Friday, 19 August 2011, Erik Hesselink wrote:
 Why exactly do you need the precision information?

 Empirical measurements (e.g., sizes of some fields in hectares) are
 precise only to a certain level of measurement error. Thus, the area
 measurements 1 ha and 1.000 ha are not equivalent or interchangeable.
 Database engines recognize this fact by providing different data types
 for rational numbers and fixed-precision decimal numbers.

 The bottom line for me is that the conversion of a fixed-precision
 decimal number as a rational is both throwing away information (the
 precision) as well as introducing bogus information (the notion that the
 result value has greater --- i.e., infinite --- precision that was in
 fact intended when that value was stored).

Note that PostgreSQL also doesn't work with decimals as precision:

postgres=# select 1::decimal(4,2) * 1::decimal(4,2);
?column?
--
   1.
(1 row)

That should be 1.00 instead if you want the precision correctly represented.

Perhaps a solution would be to not treat the database precision as
your primary source of information, but represent that in Haskell
using some data type that correctly propagates precision information,
and marshall your database data to and from that. This means some
duplication of information (precision in both database and Haskell)
but you do the same with NULL and Maybe, etc. I guess that's inherent
to (the way HDBC does) database access.

Erik

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


Re: [Haskell-cafe] Can I have a typeclass for topological spaces?

2011-08-19 Thread Tilo Wiklund
You may want to, instead, check out the methods of point-free topology
(also known as pointless topology) where you, basically, study
topological spaces in terms of their open-set lattices.

This allows you to use a more algebraic language which probably fits
better into Haskell (I think this is used, for example, when studying
topology within type theories). A search for stone-duality should give
you somewhere to start (I know there are a sequence of posts on
http://topologicalmusings.wordpress.com/ on the subject).

Somewhat less known is the theory of formal topology (see for example
n-lab http://ncatlab.org/nlab/show/formal+topology). Which might also
be an approach to doing some topology in Haskell.

Hope that's of some help :)

On 11/08/2011, Grigory Sarnitskiy sargrig...@ya.ru wrote:
 Hello! I just wonder whether it is possible to have a typeclass for
 topological spaces?

 ___
 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 is Random in System?

2011-08-19 Thread Ryan Newton
 Yep, but don't conflate determinism with splitting. In the imperative
 world, you normally know how many CPUs you have, so you initialize one PRNG
 per CPU, and simply go from there; there's no need for splitting. In the
 parallel community, people are going out of their way to *avoid*
  splitting.


I'm having trouble thinking of scenarios where per-CPU does the trick.  Do
you mean one per pthread rather than one per CPU?

In the Cilk case, you've got to deal with work stealing of course.  So you
want rand() to generate a result that is determined by the current
stack-frame's position in the binary-tree of spawns.  In the work I was
referring to:


http://groups.csail.mit.edu/sct/wiki/index.php?title=Other_Projects#Deterministic_Parallel_Random-Number_Generation

... they try a bunch of different methods and I can't remember if any of
them split the RNG eagerly as they go down the spawn tree or if they just
record the tree-index on the way down and then read it out when they
generated randoms.  (I think the latter.)

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


Re: [Haskell-cafe] custom SQL-to-Haskell type conversion in HDBC

2011-08-19 Thread Brandon Allbery
On Fri, Aug 19, 2011 at 11:45, Erik Hesselink hessel...@gmail.com wrote:

 Note that PostgreSQL also doesn't work with decimals as precision:

 postgres=# select 1::decimal(4,2) * 1::decimal(4,2);
 ?column?
 --
   1.
 (1 row)

 That should be 1.00 instead if you want the precision correctly
 represented.


Er?  Last I checked, that was exactly how precision worked over
multiplication; otherwise you are incorrectly discarding precision present
in the original values.  Unless you're assuming the OP actually wants an
incorrect flat precision model

-- 
brandon s allbery  allber...@gmail.com
wandering unix systems administrator (available) (412) 475-9364 vm/sms
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Question about data

2011-08-19 Thread Paul Reiners
I've created a simple type declaration:

data MathExpression = Float
| Add MathExpression MathExpression
| Subtract MathExpression MathExpression
| Multiply MathExpression MathExpression
| Divide MathExpression MathExpression
  deriving (Show)

Now how do I create an instance of MathExpression which is just a Float?

This doesn't work:

*Main let pi = 3.14 :: MathExpression

interactive:1:10:
No instance for (Fractional MathExpression)
  arising from the literal `3.14'
Possible fix:
  add an instance declaration for (Fractional MathExpression)
In the expression: 3.14 :: MathExpression
In an equation for `pi': pi = 3.14 :: MathExpression
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Question about data

2011-08-19 Thread Thomas DuBuisson
This is not a valid data declaration.  You can't have a Float field
without any constructor name and have it still of type
MathExpression.  I suggest you do something like:

data MathExpr = MathFloat Float


So you may declare pi:

let mathPi = MathFloat pi  -- note pi is defined in the prelude alread


Cheers,
Thomas

On Fri, Aug 19, 2011 at 1:40 PM, Paul Reiners paul.rein...@gmail.com wrote:
 I've created a simple type declaration:

 data MathExpression = Float
     | Add MathExpression MathExpression
     | Subtract MathExpression MathExpression
     | Multiply MathExpression MathExpression
     | Divide MathExpression MathExpression
       deriving (Show)

 Now how do I create an instance of MathExpression which is just a Float?

 This doesn't work:

 *Main let pi = 3.14 :: MathExpression

 interactive:1:10:
     No instance for (Fractional MathExpression)
   arising from the literal `3.14'
     Possible fix:
   add an instance declaration for (Fractional MathExpression)
     In the expression: 3.14 :: MathExpression
     In an equation for `pi': pi = 3.14 :: MathExpression



 ___
 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] Question about data

2011-08-19 Thread Jason Dagit
On Fri, Aug 19, 2011 at 1:45 PM, Thomas DuBuisson
thomas.dubuis...@gmail.com wrote:
 This is not a valid data declaration.  You can't have a Float field
 without any constructor name and have it still of type

And the reason why it accepts 'data MathExpr = Float', is because data
constructors and types live in separate namespaces.  There is already
a type called Float in the Prelude, but there is no 'Float' data
constructor.

(Just pointing this out in case it's not obvious!)

Jason

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


Re: [Haskell-cafe] Question about data

2011-08-19 Thread Stephen Tetley
Others have pointed out your first bug.

To get floating-point numeric literals you will need to define
instances of Num and then Fractional for your symbolic type.

On 19 August 2011 21:40, Paul Reiners paul.rein...@gmail.com wrote:

 *Main let pi = 3.14 :: MathExpression


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


Re: [Haskell-cafe] Question about data

2011-08-19 Thread MigMit
Your MathExpression data type has nothing to do with numbers of any kind. Your 
Float data constructor doesn't mean that float numbers are a part of your 
type; instead it means that you have a SINGLE value of type MathExpression, and 
this value is named Float.

You should modify your data declaration as data MathExpression = Float Float | 
…, and after that you can write something like a = Float 4.2, which would 
automatically make a a value of type MathExpession.

Отправлено с iPad

20.08.2011, в 0:40, Paul Reiners paul.rein...@gmail.com написал(а):

 I've created a simple type declaration:
 
 data MathExpression = Float
 | Add MathExpression MathExpression
 | Subtract MathExpression MathExpression
 | Multiply MathExpression MathExpression
 | Divide MathExpression MathExpression
   deriving (Show)
 
 Now how do I create an instance of MathExpression which is just a Float?
 
 This doesn't work:
 
 *Main let pi = 3.14 :: MathExpression
 
 interactive:1:10:
 No instance for (Fractional MathExpression)
   arising from the literal `3.14'
 Possible fix:
   add an instance declaration for (Fractional MathExpression)
 In the expression: 3.14 :: MathExpression
 In an equation for `pi': pi = 3.14 :: MathExpression
 
 
 ___
 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] Simon PJ in Australia

2011-08-19 Thread Albert Y. C. Lai

On 11-08-19 06:54 AM, Arlen Cuss wrote:

You heard it here first; Simon's down here in Aus to eat pizza,
university departments, Haskell users groups. Will he leave nothing left!?


He is not eating newbies. But I am. I love newbies.

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


Re: [Haskell-cafe] Simon PJ in Australia

2011-08-19 Thread Brandon Allbery
On Fri, Aug 19, 2011 at 20:23, Albert Y. C. Lai tre...@vex.net wrote:

 On 11-08-19 06:54 AM, Arlen Cuss wrote:

 You heard it here first; Simon's down here in Aus to eat pizza,
 university departments, Haskell users groups. Will he leave nothing
 left!?


 He is not eating newbies. But I am. I love newbies.


Hasn't he (or his brainchild) already eaten Haskell users groups?

-- 
brandon s allbery  allber...@gmail.com
wandering unix systems administrator (available) (412) 475-9364 vm/sms
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe