Re: [Haskell-cafe] Partially applied type synonyms in instance heads

2006-10-29 Thread Nicolas Frisby

Haskell's type system does not directly allow eta expansion, i.e.


instance Map (\x y - [(x, y)]) a b where
  ...


is not legal.



The straight-forward way to tackle this is with a newtype declaration, i.e.


newtype Assoc a b = Assoc [(a, b)]

instance Map Assoc a b where
  ...


works as expected. There's an avenue for you to continue with if you like.

In regards to what GHC was trying to tell you with its error message:
type synonyms (like your Assoc) can never be partially applied. In
your instance, Assoc is not applied to a and b (don't let the adjaceny
fool you), it's just sitting by itself... the most lonely version of
partial application. Hence it croaks.

Hope that helps,
Nick

ps - I've never pondered why it is that type synonyms can't be
partially applied. I'm sure someone will pipe up with the answer.

On 10/28/06, Mathieu Boespflug [EMAIL PROTECTED] wrote:

Hi everyone,

I'm running into trouble with type synonyms in instance heads and I
can't figure out what the resulting error message means. The case I'm
considering is as follows:

-- hoist a and b to class variables so that instances declarations may
-- constrain them.
class Map m a b where
toAssoc :: m a b - [(a, b)]
fromAssoc :: [(a, b)] - m a b

type Assoc a b = [(a, b)]

instance Map Assoc a b where
toAssoc = id
fromAssoc = id

The class Map is used to allow translation from one map type to
another (FiniteMap, arrays, etc...) by means of expressing the map as
an association list. Useful for defining isomorphisms and so on. Now
I'd like to define an association list as itself a trivial instance of
Map class, but I cannot do so without wrapping the type of an
association list, [(a, b)], behind a type synonym, as I'm not aware of
any way of writing a type constructor of kind (* - * - *)
constructing the type [(a, b)].
But when compiling the above code with GHC I get the following error:

Map.hs:9:0:
Type synonym `Assoc' should have 2 arguments, but has been given 0
In the instance declaration for `Map Assoc a b'

Any idea what this means? Also, is there any other way of declaring an
instance for [(a, b)] without using type synonyms?

Many thanks,

Mathieu
___
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] mapAccumL - find max in-sequence subsequence

2006-10-29 Thread jim burton



Sebastian Sylvan-2 wrote:
 
 I'm not sure I completely understand what you want, and if it needs to
 be cute (i.e. some clever one liner usage of a library function).
 But here's my get-the-job-done-solution (assuming I understood what
 you want):
 
 import Data.List
 import Data.Ord
 
 longestInSequence :: (Enum a) = [a] - Int
 longestInSequence = maximum . map (length . takeInSeq) . tails
 
 takeInSeq []  = []
 takeInSeq [x] = [x]
 takeInSeq (x:y:xs) | fromEnum (succ x) == fromEnum y = x : takeInSeq
 (y:xs)
| otherwise   = takeInSeq (x:xs)
 
 /S
 
Thanks, that's what I was looking for - and it doesn't need to be 'cute'!
-- 
View this message in context: 
http://www.nabble.com/mapAccumL---find-max-in-sequence-subsequence-tf2531704.html#a7059817
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

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


Re: [Haskell-cafe] The Read Class

2006-10-29 Thread Tiago Veloso
Yes pleaseI wold like some examples (no importance how interesting) Maybe i can work my way from there.On 28 Oct 2006, at 23:32, Daniel Fischer wrote:Hi,probably the best way is to write a parser using ReadP/ReadPrec and theninstance Read SomeType where	readPrec = yourParserIf you wish, I could send you a few examples (not very interesting, but they might help getting you going).Cheers,DanielAm Samstag, 28. Oktober 2006 23:49 schrieb Tiago Veloso: Hi,I am trying to find out how to work with the Read Class for a schoolproject, i need to declare instances of Read for a few data types.My problem is that i do not know how to do it, i mean i do not knowhow to build a Read instance, i do know about it for the Show Class.Can some one help?ThanksTiago Veloso   Tiago Veloso ___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Rank N type tutorial?

2006-10-29 Thread Jón Fairbairn
David House [EMAIL PROTECTED] writes:

 On 27/10/06, Greg Buchholz [EMAIL PROTECTED] wrote:
  I thought exists was spelled forall in Haskell?
 
 There is some confusion here,

It's the notation for data declarations that causes the
confusion. To rearrange your text a bit:

 So, for example:
 
 [forall a. a]  --  the list whose elements all have the type forall a.
 a, i.e. a list of bottom.

list of bottoms.

 forall a. [a]  --  all elements have some (the same) type a, which can
 be assumed to be any type at all by a callee.

and consequently also must be a list of bottoms.


This:

 data T = forall a. MkT a

is where the confusion comes in.

 This means that:
 
 MkT :: forall a. a - T

If the standard syntax were

 data T where
MkT :: forall a. a - T

(as for GADTs), there's be less of a problem. (it's still
misleading, because T looks like it has no variables in it,
which might lead one to conclude that MkT throws away its
argument) Equally, the natural way of writing it with the
old syntax would be:

 data T = MkT (exists a. a)

ie a T is the constructor MkT applied to some unknown type.
So people seeing the first form tend to think it means this
last.

-- which is what you said, but I think this highlights the
   source of confusion better.

-- 
Jón Fairbairn [EMAIL PROTECTED]

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


[Haskell-cafe] YAHT: Ex 9.2

2006-10-29 Thread Magnus Therning
I've been slowly making my way through Yet Another Haskell Tutorial.  As
a first introduction to the language it doesn't seem bad at all.
However, I'm wondering about the proposed solution to exercise 9.2.  The
text itself suggests using instance Monad (Either String) where, so I
arrived at

  instance Monad (Either String) where
  return a = Right a
  fail a = Left a
  Right a = f = f a
  Left a = _ = Left a

However, when loading it in ghci 6.6 I get the following error message:

 Illegal instance declaration for `Monad (Either String)'
(The instance type must be of form (T a b c)
 where T is not a synonym, and a,b,c are distinct type variables)
In the instance declaration for `Monad (Either String)'

The solution, according to the author is

  instance Monad (Either String) where
  return x = Right x
  fail s = Left s
  Right x = f = f x
  Left s = _ = Left s

Which results in exactly the same error message.

I'm suspecting this is a result of my limited grasp of Haskell's syntax
(an area where YAHT is sorely lacking).  Any tips/pointers appreciated.

/M

-- 
Magnus Therning (OpenPGP: 0xAB4DFBA4)
[EMAIL PROTECTED] Jabber: [EMAIL PROTECTED]
http://therning.org/magnus

Software is not manufactured, it is something you write and publish.
Keep Europe free from software patents, we do not want censorship
by patent law on written works.

As far as the laws of mathematics refer to reality, they are not
certain, and as far as they are certain, they do not refer to reality.
 -- Albert Einstein


pgpuAU81gQzEb.pgp
Description: PGP signature
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] YAHT: Ex 9.2

2006-10-29 Thread Nicolas Frisby

Quick fix: add this line to the top of your file

{-# OPTIONS -fglasgow-exts #-}


Having String instead of a free type variable is beyond the basic
limitations of Haskell's type classses.

However, enabling the very common Glasgow extensions expands the rules
to admit your definition. If you for some reason do not wish to add
the Glasgow extensions, the following also works.

newtype EitherStr a = ES (Either String a)

instance Monad EitherStr where
   return a = ES (Right a)
   fail a = ES (Left undefined)
   ES (Right a) = f = f a
   ES (Left a) = _ = ES (Left a)


On 10/29/06, Magnus Therning [EMAIL PROTECTED] wrote:

I've been slowly making my way through Yet Another Haskell Tutorial.  As
a first introduction to the language it doesn't seem bad at all.
However, I'm wondering about the proposed solution to exercise 9.2.  The
text itself suggests using instance Monad (Either String) where, so I
arrived at

  instance Monad (Either String) where
  return a = Right a
  fail a = Left a
  Right a = f = f a
  Left a = _ = Left a

However, when loading it in ghci 6.6 I get the following error message:

 Illegal instance declaration for `Monad (Either String)'
(The instance type must be of form (T a b c)
 where T is not a synonym, and a,b,c are distinct type variables)
In the instance declaration for `Monad (Either String)'

The solution, according to the author is

  instance Monad (Either String) where
  return x = Right x
  fail s = Left s
  Right x = f = f x
  Left s = _ = Left s

Which results in exactly the same error message.

I'm suspecting this is a result of my limited grasp of Haskell's syntax
(an area where YAHT is sorely lacking).  Any tips/pointers appreciated.

/M

--
Magnus Therning (OpenPGP: 0xAB4DFBA4)
[EMAIL PROTECTED] Jabber: [EMAIL PROTECTED]
http://therning.org/magnus

Software is not manufactured, it is something you write and publish.
Keep Europe free from software patents, we do not want censorship
by patent law on written works.

As far as the laws of mathematics refer to reality, they are not
certain, and as far as they are certain, they do not refer to reality.
 -- Albert Einstein


___
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


[Haskell-cafe] Deriving class instances using DrIFT

2006-10-29 Thread Daniel McAllansmith
Hi.

I'm trying to derive some instances using DrIFT, but it will only work for me 
when I'm deriving for types in the current file or in the prelude.

For example,

this works:

module Test where

{-! for Maybe derive : Haskell2Xml !-}


this works:

module Test where

data Foo = Foo

{-! for Foo derive : Haskell2Xml !-}


but this doesn't:

module Test where

import Data.Word

{-! for Word32 derive : Haskell2Xml !-}

It fails to load the first import, giving an error as follows:

{- Generated by DrIFT (Automatic class derivations for Haskell) -}
{-# LINE 1 Test.hs #-}
DrIFT: can't find module Data.Word

Any ideas as to why that is?


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


[Haskell-cafe] More documentation: how to create a Haskell project

2006-10-29 Thread Donald Bruce Stewart
There's been a bit of discussion on irc, lists and privately about 
about documenting publically the best practice for creating a new
Haskell project -- be that a library or an application.

Some advice is now available here:
http://haskell.org/haskellwiki/How_to_write_a_Haskell_program

Suggestions include:
* use darcs
* use cabal

But we could do with more information on:
* where to host a haskell project 
* integration of testsuites
* anything about Hackage?
* portability issues?

So have a look at the page and make some suggestions, so it will be
easier for newcomers in the future to create and contribute new
projects, that will be readily accesible, useable and adopted by the
community.

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


Re: [Haskell-cafe] More documentation: how to create a Haskell project

2006-10-29 Thread Tony Morris

Tony Morris
http://tmorris.net/



Donald Bruce Stewart wrote:
 There's been a bit of discussion on irc, lists and privately about 
 about documenting publically the best practice for creating a new
 Haskell project -- be that a library or an application.
 

Agreed.

 Some advice is now available here:
 http://haskell.org/haskellwiki/How_to_write_a_Haskell_program
 
 Suggestions include:
 * use darcs
 * use cabal
 
 But we could do with more information on:
 * where to host a haskell project 
 * integration of testsuites
 * anything about Hackage?
 * portability issues?
 
 So have a look at the page and make some suggestions, so it will be
 easier for newcomers in the future to create and contribute new
 projects, that will be readily accesible, useable and adopted by the
 community.
 

My suggestion:
The steps of reasoning as you start with a blank directory.
For example:

1) We are about to write a package called foo using Haskell so we start
with setting up a foo.cabal file (assuming you have answer what is
cabal?) and Setup.hs.
2) Then we create a src directory and set hs-source-dirs: src
3) Annotate our source with these comments for haddock.
4) If you want links to base libraries in your haddock output, do such
and such (how do you do that anyway?)
5) If this and that, then so and so...
...

Finally, there should be a bunch of files that represent the artifacts
of following these steps from a blank directory (hnop is a bit scant).

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


[Haskell-cafe] Documenting subcommunities

2006-10-29 Thread Donald Bruce Stewart
As the Haskell community grows and spreads its lambda-tipped tentacles
into new domains, I've noticed that some distinct sub-communities are
emerging.

To try to document and collect information relevant to these groups,
some new wiki pages have been created.

Alongside the 'traditional' areas of: 

http://haskell.org/haskellwiki/Haskell_in_research
http://haskell.org/haskellwiki/Haskell_in_education

There is also a growing number of users of Haskell:

http://haskell.org/haskellwiki/Haskell_in_industry
http://haskell.org/haskellwiki/Haskell_and_mathematics

If you're using Haskell for maths or in industry, and know of some
relevant resources, please feel free to add the material to the above
pages.

Alternatively, if there are subcommunities that are missing a page (hmm,
the open source community, perhaps?), then dive in and create a page
documenting this.

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


Re: [Haskell-cafe] Deriving class instances using DrIFT

2006-10-29 Thread John Meacham
On Mon, Oct 30, 2006 at 01:24:58PM +1300, Daniel McAllansmith wrote:
 I'm trying to derive some instances using DrIFT, but it will only work for me 
 when I'm deriving for types in the current file or in the prelude.

Since DrIFT can only understand haskell source code, it can't derive
instances for anything you don't have the original source to. such as
things in the pre-compiled libraries that come with ghc. you will likely
have to write out those instances by hand. 

Another possibility is that you could replicate just the data
declarations by hand, and use DrIFT -r to just spit out the derivations
and put those in a file on their own.

a long time ago DrIFT used to be able to read ghc 'hi' files, but that
has not worked in a while, it is possible not all the documentation has
been updated to reflect that.

John

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


[Haskell-cafe] Re: function types as instances of Num

2006-10-29 Thread oleg

The problem seems equivalent to the following:
http://pobox.com/~oleg/ftp/Haskell/typecast.html#local-fd
That is, the inferred type is too general to chose the appropriate
instance. The solution is also the same: either add type annotations
to restrict the inferred type (and so make it _match_ the desired
instance) -- or use local type inference. Here's the working code of
your Haskell embedding of the Forth-like stack language:

 {-# OPTIONS -fglasgow-exts #-}
 {-# OPTIONS -fallow-undecidable-instances #-}

 main = print $ test ()

 test  = square . 4

 dup  (a, b)  = (a, (a, b))
 mult (a, (b, c)) = (b*a, c)
 square = mult . dup

 instance Num c = Eq   (a - (c, b))
 instance Num c = Show (a - (c, b))
 instance (Num c, TypeCast a b) = Num  (a - (c, b)) where
  fromInteger val stack = (fromInteger val,typeCast stack)
[TypeCast elided]
 
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] More documentation: languages written in Haskell

2006-10-29 Thread Donald Bruce Stewart
I noticed today that although we have a list of most applications
written in Haskell, nowhere was there collected a page of perhaps our
best use case for Haskell: for implementing compilers and interpreters!

So here's a new 'libraries and tools' category page:

http://haskell.org/haskellwiki/Libraries_and_tools/Compilers_and_interpreters

If you know of a compiler or interpreter written in Haskell, (I think at
least a few people on this list have written one or two themselves ... ;)
please add it to the list.

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


[Haskell-cafe] Re: More documentation: languages written in Haskell

2006-10-29 Thread Max Vasin
 Donald == Donald Bruce Stewart [EMAIL PROTECTED] writes:

Donald I noticed today that although we have a list of most
Donald applications written in Haskell, nowhere was there
Donald collected a page of perhaps our best use case for Haskell:
Donald for implementing compilers and interpreters!

Donald So here's a new 'libraries and tools' category page:
Donald 
http://haskell.org/haskellwiki/Libraries_and_tools/Compilers_and_interpreters

Donald If you know of a compiler or interpreter written in
Donald Haskell, (I think at least a few people on this list have
Donald written one or two themselves ... ;) please add it to the
Donald list.

I have no login at haskell.org, so I post here. There is a Curry compiler
implemented in Haskell: The Münster Curry Compiler 
(http://danae.uni-muenster.de/~lux/curry/).

-- 
WBR,
Max Vasin.

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