Re: [Haskell-cafe] Newbie Instance Of Floating Int Error

2006-04-28 Thread Cale Gibbard
One thing to try:
type Point = (Float, Float)

The problem is that x1, y1, x2, and y2 are Ints, and so (x2-x1)^2  +
(y2-y1)^2 is also an Int, but then you try to take the square root,
which is an operation only available on floating point values (more
specifically, types in the class Floating, which also includes things
like Complex Double).

Another option is to leave the Point type as-is, but do a conversion
just before applying the sqrt, say, by applying the fromIntegral
function, which serves to convert from types in the class Integral,
like Int and Integer to any numeric type you need.
distBetween (x1,y1) (x2,y2) = sqrt . fromIntegral $ (x2-x1)^2 + (y2-y1)^2

hope this helps,
 - Cale

On 27/04/06, Aditya Siram [EMAIL PROTECTED] wrote:
 Hi all,
 I just started working with Haskell and am having some difficulties with its
 type system.
 Here is function that is supposed to calculate the distance between two
 coordinates:
 distBetween (x1,y1) (x2,y2) = sqrt((x2-x1)^2  + (y2-y1)^2)

 I am trying to explictly give it a type signature. Here is what I have tried
 and the errors generated by Hugs:

 type Point = (Int,Int)
 distBetween :: Point - Point - Float
 ERROR - Type error in explicitly typed binding
 *** Term   : distBetween
 *** Type   : Point - Point - Int
 *** Does not match : Point - Point - Float

 distBetween :: Point - Point - Int
 Instance of Floating Int required for definition of distBetween

 Any help is appreciated...
 Deech


 ___
 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] Newbie Instance Of Floating Int Error

2006-04-28 Thread Jared Updike
It looks like somewhere else in your program (or a type signature
somewhere) is trying to force the result of sqrt to be an Int which
won't work since square roots are irrational (represented by the
computer as a Float or Double).

You might try (1) making sure the place where distBetween is used
isn't trying to use only Ints or Integers and (2) taking off explicit
type signatures and seeing if that works (the compiler can usually get
things working for you as long as you don't give it misinformation in
type signatures). Also, a more useful type of Point if you are taking
distances would be

type Point = (Float,Float)

instead (or you can leave that out because the function type for
distBetween will be inferred to be the right thing, i.e.
(Float,Float) is already a valid type without needing to be named).

Hope that helps,
  Jared.
--
http://www.updike.org/~jared/
reverse )-:

On 4/27/06, Aditya Siram [EMAIL PROTECTED] wrote:
 Hi all,
 I just started working with Haskell and am having some difficulties with its
 type system.
 Here is function that is supposed to calculate the distance between two
 coordinates:
 distBetween (x1,y1) (x2,y2) = sqrt((x2-x1)^2  + (y2-y1)^2)

 I am trying to explictly give it a type signature. Here is what I have tried
 and the errors generated by Hugs:

 type Point = (Int,Int)
 distBetween :: Point - Point - Float
 ERROR - Type error in explicitly typed binding
 *** Term   : distBetween
 *** Type   : Point - Point - Int
 *** Does not match : Point - Point - Float

 distBetween :: Point - Point - Int
 Instance of Floating Int required for definition of distBetween

 Any help is appreciated...
 Deech


 ___
 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] database access recommendation

2006-04-28 Thread Bulat Ziganshin
Hello Brock,

Thursday, April 27, 2006, 7:45:16 PM, you wrote:
 I looked at http://www.haskell.org/haskellwiki/Libraries_and_tools, and

suffice it to say that this page don't reflects current state of the
art. during many years it was not updated and when it was moved to the
wiki half-year ago it's contents remains the stone-age

better sources of information are HCAR (Haskell Communities and Activities 
Report,
http://www.haskell.org/communities/11-2005/html/report.html) and HWN
(Haskell Weekly News, http://haskell.org/haskellwiki/HWN)

as one person said, There are three active database libraries: HDBC,
HSQL and Takusen.. i've included here last announces on two of them
(just searched my mail archives for SQL):



I'm pleased to (at long last) announce the release of HDBC version
0.99.2, along with 0.99.2 versions of all database backends.  If
things go well, after a few weeks of testing, this version will become
HDBC 1.0.0.

HDBC is a multi-database interface system for Haskell -- more on it
below.

Since 0.99.0, several major things have been updated or enhanced:

 * Complete rework of memory management system.

 * Standardized memory management system for all database backends.

 * Support for querying metadata (type, size, etc.) about columns
   both in result sets and in database tables

 * Support for querying the level of transaction support in the
   underlying DB

 * ODBC driver has support for working with databases such as
   MySQL that don't support transactions

 * Testsuite enhancements for all the above

I believe that these modifications will make HDBC suitable as a
full-fledged backend for HaskellDB.

HDBC is available from:

  http://quux.org/devel/hdbc
  gopher://quux.org/1/devel/hdbc

Version 0.99.2 has also been uploaded to Debian unstable.

Features of HDBC


*  Ability to use replacable parameters to let one query be
   executed multiple times (eliminates the need for an escape
   function)
* Ability to access returned rows by column number
* Ability to read data from the SQL server on-demand rather than
   reading the entire result set up front
* HUnit testsuite for each backend driver
* Well-defined standard API and easy backend driver implementation
* Lazy reading of the entire result set (think hGetContents, but
   for the results of SELECT) (see sFetchAllRows)
* Support for translation between Haskell and SQL types
* Support for querying database server properties
* Add-on package (hdbc-missingh) to integrate with MissingH,
   providing a database backend for AnyDBM.
* Support for querying metadata such as column names. 

In addition, there is extensive documentation for HDBC.

Backend drivers exist for Sqlite v3, PostgreSQL, and ODBC.  MySQL is
supported via the ODBC driver and the ODBC testsuite passes against
MySQL (saving the transaction tests, which aren't supported by MySQL).
In addition, there is a odbc-missingh package that can turn and HDBC
database into an AnyDBM backend for MissingH.  (Sqlite3 could be very
handy there)

Darcs repositories are available for all of this at
http://darcs.complete.org/






I am pleased to announce the HSQL library version 1.6. The HSQL is a
simple library, which provides interface to multiple databases. MySQL,
PostgreSQL, ODBC, SQLite and MSI (new) are currently supported.
 
 
What is new? 
~~
 
1. HSQL is fully Cabalized.

2. Windows users don't need to have cygwin in order to build HSQL. The
old build system was using ./configure script which is replaced with
hooks in ./Setup.lhs script.

3. HSQL is split into multiple Cabal packages. There is one common
package 'hsql' and multiple database specific packages: hsql-odbc,
hsql-postgresql, hsql-mysql, hsql-sqlite, hsql-sqlite3, hsql-msi

4. There are two new database frontends: SQLite3 and MSI. The SQLite3
frontend is for SQLite version 3.0 and above. The old SQLite frontend
still exists. MSI is fontend to Microsoft Installer database. Each
.msi package is a relational database which you can query and modify
using HSQL.



[Haskell] ANNOUNCE: HSQL 1.7 released

What is new?
~~

1. Driver for Oracle

2. getFieldValueMB is deprecated. Now there is the instance declaration:

instance SqlBind a = SqlBind (Maybe a)

It allows to use getFieldValue instead of getFieldValueMB.
Thanks to Frederik Eaton for this idea.

3. Database.HSQL.SQLite is renamed to Database.HSQL.SQLite2. The trouble
was that with Hugs for each module with FFI is generated an extra .dll/.so
library. In this case the library is SQLite.dll which on Windows overlaps
with the name of the real sqlite.dll library.

Home page
~

http://htoolkit.sourceforge.net

Download from
~

https://sourceforge.net/project/showfiles.php?group_id=65248package_id=93958

-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

___
Haskell-Cafe mailing list

Re: [Haskell-cafe] short yet featureful grep

2006-04-28 Thread David House

On 27/04/06, John Meacham [EMAIL PROTECTED] wrote:

my favorite example is the featureful yet short grep, supporting quite a
few non-trivial options as well as a detailed '--help' message. :)


Does getOptions really take an arbitrary n-tuple? Why? That seems a
very odd way of doing things. The only advantage I can think of over
lists is that tuples don't have to be typically homogeneous, but I
would have thought that you could get your ?? and == operators to
spit out the correct types.

--
-David House, [EMAIL PROTECTED], http://xmouse.ithium.net
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] database access recommendation

2006-04-28 Thread Donald Bruce Stewart
bulat.ziganshin:
 Hello Brock,
 
 Thursday, April 27, 2006, 7:45:16 PM, you wrote:
  I looked at http://www.haskell.org/haskellwiki/Libraries_and_tools, and
 
 suffice it to say that this page don't reflects current state of the
 art. during many years it was not updated and when it was moved to the
 wiki half-year ago it's contents remains the stone-age
 
 better sources of information are HCAR (Haskell Communities and Activities 
 Report,
 http://www.haskell.org/communities/11-2005/html/report.html) and HWN
 (Haskell Weekly News, http://haskell.org/haskellwiki/HWN)

I'm not sure this is fair.

About a month ago I went through the entire HWN archives, the haskell@
archives back to 1990 (Check the Old_news page!) and the last HCAR,
adding over 100 entries to the libraries page.

So, I argue it is the most complete list we have.

And if anything's missing, you know how to edit the wiki.

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


Re[2]: [Haskell-cafe] GetOpt

2006-04-28 Thread Bulat Ziganshin
Hello Anton,

Friday, April 28, 2006, 12:54:44 AM, you wrote:

 I really trying to avoid imperative approach. I do have a terribly big
 experience in imperative programming (by the way, you might know one 
 application that I made about 3 years ago. It is Uni-K Sensei for

no. but may be you are heard about ARJZ? :)

 windows). Now, I am breaking my previous habits just to think wider and
 more effective.

yes, yes. but you should know that haskell still are perfect
imperative language and when pure functional approach will be not
enough for your program, you can combine both ways

 Well, I do not care too much about high-speed. My main goal is to write
 a prototype of the language that I am creating. It is a kind of 
 Domain-Specific language. I decided to start from a simple thing. A 
 converter of pgn files with chess notation to javascript to visualize 
 it. Just to have some practice.

if you don't care about speed and write text-conversion program, pure
functional approach may be enough. just use results of GetOpt as
argument to all the routines that depends on any program options

 my own option-processing routines, it's just about 50 lines long
 (great demonstration of Haskell power!). all processed options are
 record in one large record that is passed around all the program. if
 you get accustomed to global variables, it's using in Haskell is
 possible but that is not the best way. you can also use implicit
 parameters (at least in hugs and ghc), but this again makes data
 dependencies somewhat non-understandable

   
 Thank you very much. I will see this approach as well. I am still pretty
 concern of using records instead of lists.

what you mean?

 btw, i suggest you to use WinHugs for debugging program and ghc for
 final compilation. this makes faster development time together with
 faster final executable. moreover, making your program compatible with
 both environments is almost ensure that it will be compatible with
 coming Haskell standard, Haskell-prime
   
 Thanks again. I do not use Windows any more. I use Mac or different 
 Unices. I do use ghc everywhere I work with Haskell. For debugging I use
 ghci. Well, and everything within GNU Emacs.

you can use hugs, it works with many environments. according to my
tests, it loads programs 10 times faster than ghci



-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] database access recommendation

2006-04-28 Thread Bulat Ziganshin
Hello Brock,

Thursday, April 27, 2006, 7:45:16 PM, you wrote:

 I'm teaching myself Haskell, and was wondering if anyone could recommend
 a library for accessing databases, PostgreSQL in particular.

as Ketil Malde wrote to me in private mail, there is at least one more
lib (aside from HDBC/HSQL/Takusen) - HaskellDB. i'm sorry that i have
citated phrase that can be no (more) true

-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re: [Haskell-cafe] short yet featureful grep

2006-04-28 Thread John Meacham
On Fri, Apr 28, 2006 at 08:47:40AM +0100, David House wrote:
 On 27/04/06, John Meacham [EMAIL PROTECTED] wrote:
 my favorite example is the featureful yet short grep, supporting quite a
 few non-trivial options as well as a detailed '--help' message. :)
 
 Does getOptions really take an arbitrary n-tuple? Why? That seems a
 very odd way of doing things. The only advantage I can think of over
 lists is that tuples don't have to be typically homogeneous, but I
 would have thought that you could get your ?? and == operators to
 spit out the correct types.

Because the entire point of the module is to not only be type-safe, but
to infer your intent from the type. if everything conformed to the same
type, you wouldn't be able to ensure you lined up your arguments and
your options properly and worse, you wouldn't be able to use the results
directly as youd have to wrap them in some container. each of the return
values is of a different type.

So, the entire point of the module was to not use a list. unlike the
other options out there. :) that is what makes it neat and enables very
concise, very typesafe, code.

tuples arn't particularly special, you can use HLists with the
appropriate instances for instance. 

John



-- 
John Meacham - ⑆repetae.net⑆john⑈
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re[2]: [Haskell-cafe] database access recommendation

2006-04-28 Thread Bulat Ziganshin
Hello Donald,

Friday, April 28, 2006, 12:29:38 PM, you wrote:

  I looked at http://www.haskell.org/haskellwiki/Libraries_and_tools, and
 
 suffice it to say that this page don't reflects current state of the
 art. during many years it was not updated and when it was moved to the
 wiki half-year ago it's contents remains the stone-age

 About a month ago I went through the entire HWN archives, the haskell@
 archives back to 1990 (Check the Old_news page!) and the last HCAR,
 adding over 100 entries to the libraries page.

 So, I argue it is the most complete list we have.

GREAT! but you don't announced this work on the haskell list, so noone
can know about it


-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


RE: [Haskell-cafe] database access recommendation

2006-04-28 Thread Brock Peabody
Hi Bulat,

Thanks for all the information.  I'm giving HDBC a try as it seems to be
the most actively maintained and because I was able to install it.

Regards,
Brock

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


[Haskell-cafe] Saving a data structure to a file

2006-04-28 Thread Neil Mitchell

Hi,

I have a program which needs to cache intermediate data structures to
a file (finite, non-cyclic, relatively simple, around ~100Kb when
shown). Is there any easy way to acheive this?

The current approach I am using is to add deriving Read, Show to all
the data structures, and then

writeFile output.txt (show x)
read = readFile output.txt

The problem is that this is too slow, and itsn't lazy. Is there any
way to do better than this? I can imagine something like
showBinary/readBinary which did this using binary files directly, but
is there anything that does this?

I'd like it to work with GHC and Hugs at least, and the less extra
code I have to write the better :)

Thanks

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


Re: [Haskell-cafe] Newbie Instance Of Floating Int Error

2006-04-28 Thread Evan Martin
On 4/28/06, Aditya Siram [EMAIL PROTECTED] wrote:
 type Point = (Int,Int)
 distBetween :: Point - Point - Float
 ERROR - Type error in explicitly typed binding
 *** Term   : distBetween
 *** Type   : Point - Point - Int
 *** Does not match : Point - Point - Float

 distBetween :: Point - Point - Int
 Instance of Floating Int required for definition of distBetween

It's saying that you explicitly gave the function the type Point -
Point - Int but that it actually has Point - Point - Int.

If you look at the type of sqrt:
  Prelude :t sqrt
  sqrt :: (Floating a) = a - a
You'll see that it returns a floating-point number.

(Also, a minor style point:  you should probably get in the habit of
putting a space between the sqrt and its arguments.  It'll make more
sense as you gain more experience.)
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Saving a data structure to a file

2006-04-28 Thread Bulat Ziganshin
Hello Neil,

Friday, April 28, 2006, 7:59:22 PM, you wrote:

 I have a program which needs to cache intermediate data structures to
 a file (finite, non-cyclic, relatively simple, around ~100Kb when
 shown). Is there any easy way to acheive this?

use NewBinary (darcs get http://www.n-heptane.com/nhlab/repos/NewBinary/)
or jhc's Binary module together with DrIFT to generate Binary
instances. these modules need minimal tweaks to implement Hugs compatibility

code generated by DrIFT will use strict get. if you want to get lazy
reading, you can replace get/put_ with lazyGet/lazyPut in appropriate
instances

in order to make it run faster, you should work with memory buffer
and read/write entire buffer from/to file:

writing:
  bh - openBinMem 1 undefined
  lazyPut bh data
  ... put more data
  writeBinMem bh filename

reading:
  bh - readBinMem filename
  data - lazyGet bh
   get more data

-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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