Re: [Haskell-cafe] more on my ghc package issues

2008-04-12 Thread Galchin, Vasili
1) I did an Ubuntu purge followed by an install. Afterwards I rebuilt ghc
6.8.2. The same d*mn  "unknown package: unix-2.3.0.0" message when I try to
build

unix

 and

bytestring   via runhaskell Setup.hs configure.

2) This strongly looks like the package database manager, i.e. ghc-pkg.
Source please so I can understand where this d*amn "unknown package:
unix-2.3.0.0" message is coming from and why?

3) Serious rant mode on ... I am a computer industry veteran(decades) who is
trying to convince, coggle, etc. younger colleagues about the usefulness of
FPLs for correctness, etc, and then => "unknown package ".

V.

On Sat, Apr 12, 2008 at 11:30 AM, Brandon S. Allbery KF8NH <
[EMAIL PROTECTED]> wrote:

>
> On Apr 12, 2008, at 12:27 , Galchin, Vasili wrote:
>
> > [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0$ runhaskell Setup.hs cleanup
> > unknown package: unix-2.3.0.0
> >
> > no  it doesn't.
> >
>
> I suspect the Cabal stuff has a dependency on the unix package (at least
> on POSIXish systems, probably via the filepath stuff) and by deregistering
> unix-2.3.0.0 which Cabal was built against you broke it.  Probably you need
> to do a full reinstall of GHC to recover at this point.
>
>
> --
> brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
> system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
> electrical and computer engineering, carnegie mellon universityKF8NH
>
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] help understanding pj-lester-book

2008-04-12 Thread Bernie Pope


On 13/04/2008, at 12:09 AM, minh thu wrote:

Hi!

I don't understand something in there :

pj-lester-book :
Implementing functional languages: a tutorial
by Simon Peyton Jones and David Lester,
available at http://research.microsoft.com/~simonpj/Papers/pj- 
lester-book/


eval/apply :
Making a Fast Curry: Push/Enter vs. Eval/Apply for Higher-order  
Languages

by Simon Marlow and Simon Peyton Jones,
available at http://www.haskell.org/~simonmar/papers/

The introduction in eval/apply states the arity of a function and the
number of arguments in a call can match or differs (and it should be
dealt with).

In pj-lester-book (bottom of page 46 and top of page 47), it is stated
that if the program has been type-cheched, the underflow check is
unnecessary.
When continuing to the G-machine then to the TIM-machine chapters, I
haven't found discussion of an arity-mismatch.

What am I missing ?


Hi Minh,

If I understand the pj-lester book properly, what they are saying is:  
if you have an
expression which is a function application, and type checking has  
determined that
the result of the expression is _not a function_, then you can be  
sure that the
outermost redex in the expression has enough arguments. If it is not  
a function

then it cannot be a partial application. Thus you don't have to
do the underflow check for that redex. You either have a saturated  
application or
an over saturated application, but either way there is guaranteed to  
be enough

arguments.

Unfortunately, instead of saying "not a function", they say "a  
number, or say, a list".


If you are writing a compiler, and you are about to generate code for  
a function application,
and the type checker tells you the result is not a function, then you  
can omit generating

the code for the underflow test - which is a performance gain.

I believe the eval/apply paper is referring to the general case of a  
function application,
where you don't always know that the result is not a function. For  
example,
suppose you are generating code for the "map" function. In the body  
of "map" you have:


   case list of
  Nil -> Nil
  Cons x xs -> Cons (f x) (map f xs)

In the application (f x), you can't statically determine if it is  
saturated or not, because it depends on
the arity of the function subsituted for "f", which is of course  
unknown. (You could turn it into a
known by doing an arity-based specialisation of the program, but that  
is a fairly heavyweight

option, which would require multiple versions of functions like map.)

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


Re: [Haskell-cafe] install trouble with SDL on win32+cygwin

2008-04-12 Thread Jake Mcarthur

On Apr 12, 2008, at 9:48 PM, Conal Elliott wrote:


If not, is GLFW the recommended cross-platform GL toolkit?


Don't forget there is GLUT as well.

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


Re: [Haskell-cafe] install trouble with SDL on win32+cygwin

2008-04-12 Thread Conal Elliott
Now I have sdl-config, but still not able to build.

Does *anyone* have the SDL package running on Windows?

If not, is GLFW the recommended cross-platform GL toolkit?

Thanks,  - Conal

On Fri, Apr 11, 2008 at 8:55 PM, Luke Palmer <[EMAIL PROTECTED]> wrote:

> 2008/4/11 Conal Elliott <[EMAIL PROTECTED]>:
> > I'm trying to install the SDL package (on win32+cygwin), and configure
> isn't
> > able to find my SDL.dll, though it's on my PATH.  Any ideas?  - Conal
> >
> > bash-3.2$ cabal install SDL
> > 'SDL-0.5.3' is cached.
> >  [1 of 1] Compiling Main ( Setup.lhs, dist\setup/Main.o )
> > Linking dist\setup\setup.exe ...
> > Configuring SDL-0.5.3...
> > checking for sdl-config... no
>
> I currently am not running cygwin, so I could be wrong, but the lack
> of sdl-config is a red flag.  Have you installed sdl and sdl-devel (I
> think those are the package names) with the cygwin installer yet?
>
> Luke
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANNOUNCE: Generic Haskell 1.80 (Emerald)

2008-04-12 Thread Brandon S. Allbery KF8NH


On Apr 12, 2008, at 13:33 , Thomas van Noort wrote:

On 12/04/2008, Thomas van Noort <[EMAIL PROTECTED]> wrote:


That's a good question. Unfortunately, only Haskell98 types are
currently
 supported by the Generic Haskell compiler.


I thought constrained types were Haskell 98, but now I'm in doubt...


language. Generic Haskell is fully reflexive with respect to the types
that are definable in Haskell 98, except for constraints in data-type
definitions. So a data type of the form

data Eq a => Set a = NilSet | ConsSet a (Set a)

is not dealt with correctly. However, constrained data types are a  
corner

case in Haskell and can easily be simulated using other means.


I was under the impression "corner case" here means that H98 lets you  
write it but doesn't handle it very sanely (a GHC-specific extension  
being needed to achieve that).


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon universityKF8NH


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


Re: [Haskell-cafe] ANNOUNCE: Generic Haskell 1.80 (Emerald)

2008-04-12 Thread Thomas van Noort
> On 12/04/2008, Thomas van Noort <[EMAIL PROTECTED]> wrote:
>
>> That's a good question. Unfortunately, only Haskell98 types are
>> currently
>>  supported by the Generic Haskell compiler.
>
> I thought constrained types were Haskell 98, but now I'm in doubt...

I'm not 100% sure either, but according to the Haskell98 language report,
constrained types are not part of Haskell98,

http://haskell.org/onlinereport/basic.html ,

but are described as GHC language features,

http://www.haskell.org/ghc/docs/latest/html/users_guide/data-type-extensions.html

>
>>  But at first sight, implementing support for parametric types with
>> class
>>  constraints is not too hard. Class constraints of a parametric type
>> need
>>  to be propagated to its generated structure type.
>
> Certainly, but there are a few difficulties for higher-kinded types.
> An arguable solution: http://portal.acm.org/citation.cfm?id=1159868
>
> The reason I mention this is because Scrap your Boilerplate supports
> them whereas GH does not, and I'm not aware this has been taken into
> account when comparing these two approaches in the work cited by Bulat
> on this thread.
>

This has certainly been taken into account when comparing approaches to
generic programming. I quote from page 18/19 from the work you and Bulat
cited:

==
Full reflexivity. A generic programming language is fully reflexive if a
generic function can be used on any type that is definable in the
language. Generic Haskell is fully reflexive with respect to the types
that are definable in Haskell 98, except for constraints in data-type
definitions. So a data type of the form

data Eq a => Set a = NilSet | ConsSet a (Set a)

is not dealt with correctly. However, constrained data types are a corner
case in Haskell and can easily be simulated using other means.
Furthermore, Nogueira [69] shows how to make Generic Haskell work for data
types with constraints.
==

Thus, full reflexivity of an approach is taken into account. This suggests
constrained types are part of Haskell98. So, I'm a bit confused at the
moment as well.

Regards,
Thomas

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


Re: [Haskell-cafe] ANNOUNCE: Generic Haskell 1.80 (Emerald)

2008-04-12 Thread Pablo Nogueira
On 12/04/2008, Thomas van Noort <[EMAIL PROTECTED]> wrote:

> That's a good question. Unfortunately, only Haskell98 types are currently
>  supported by the Generic Haskell compiler.

I thought constrained types were Haskell 98, but now I'm in doubt...

>  But at first sight, implementing support for parametric types with class
>  constraints is not too hard. Class constraints of a parametric type need
>  to be propagated to its generated structure type.

Certainly, but there are a few difficulties for higher-kinded types.
An arguable solution: http://portal.acm.org/citation.cfm?id=1159868

The reason I mention this is because Scrap your Boilerplate supports
them whereas GH does not, and I'm not aware this has been taken into
account when comparing these two approaches in the work cited by Bulat
on this thread.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] more on my ghc package issues

2008-04-12 Thread Galchin, Vasili
I was afraid of the install. Hopefully with the Ubuntu package manager it
will be fairly painless.

Thanks, Vasili

On Sat, Apr 12, 2008 at 11:30 AM, Brandon S. Allbery KF8NH <
[EMAIL PROTECTED]> wrote:

>
> On Apr 12, 2008, at 12:27 , Galchin, Vasili wrote:
>
> > [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0$ runhaskell Setup.hs cleanup
> > unknown package: unix-2.3.0.0
> >
> > no  it doesn't.
> >
>
> I suspect the Cabal stuff has a dependency on the unix package (at least
> on POSIXish systems, probably via the filepath stuff) and by deregistering
> unix-2.3.0.0 which Cabal was built against you broke it.  Probably you need
> to do a full reinstall of GHC to recover at this point.
>
>
> --
> brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
> system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
> electrical and computer engineering, carnegie mellon universityKF8NH
>
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] more on my ghc package issues

2008-04-12 Thread Brandon S. Allbery KF8NH


On Apr 12, 2008, at 12:27 , Galchin, Vasili wrote:
[EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0$ runhaskell Setup.hs  
cleanup

unknown package: unix-2.3.0.0

no  it doesn't.


I suspect the Cabal stuff has a dependency on the unix package (at  
least on POSIXish systems, probably via the filepath stuff) and by  
deregistering unix-2.3.0.0 which Cabal was built against you broke  
it.  Probably you need to do a full reinstall of GHC to recover at  
this point.



--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon universityKF8NH


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


Re: [Haskell-cafe] more on my ghc package issues

2008-04-12 Thread Galchin, Vasili
[EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0$ runhaskell Setup.hs cleanup
unknown package: unix-2.3.0.0

no  it doesn't.

Vasili

On Sat, Apr 12, 2008 at 9:20 AM, Brent Yorgey <[EMAIL PROTECTED]> wrote:

> ]
> >
> > [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0$ runhaskell Setup.hs
> > configure
> > unknown package: unix-2.3.0.0
> >
>
> I suggested this in my other message, before I saw this one, but just to
> be sure: does it help to do 'runhaskell Setup.hs clean' before doing the
> configure step?
>
> -Brent
>
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANNOUNCE: Generic Haskell 1.80 (Emerald)

2008-04-12 Thread Thomas van Noort
That's a good question. Unfortunately, only Haskell98 types are currently
supported by the Generic Haskell compiler.

But at first sight, implementing support for parametric types with class
constraints is not too hard. Class constraints of a parametric type need
to be propagated to its generated structure type.

Regards,
Thomas

> On 12/04/2008, Thomas van Noort <[EMAIL PROTECTED]> wrote:
>
>>  Generic Haskell includes the following features:
>>
>>  * type-indexed values -- generic functions that can be
>>instantiated on all Haskell data types.
>^^^
>
> I have perused the manual and wonder if parametric types with class
> constraints are now supported or are not considered Haskell types. I'm
> thinking of types such as
>
> data Ord a => BinTree a = Leaf | Node a (BinTree a) (BinTree a)
> data Functor f => GRose f a = GLeaf | GNode a (f(GTree f a))
>

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


Re: [Haskell-cafe] more on my ghc package issues

2008-04-12 Thread Brent Yorgey
]
>
> [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0$ runhaskell Setup.hs configure
> unknown package: unix-2.3.0.0
>

I suggested this in my other message, before I saw this one, but just to be
sure: does it help to do 'runhaskell Setup.hs clean' before doing the
configure step?

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


Re: [Haskell-cafe] library version problem

2008-04-12 Thread Brent Yorgey
On Fri, Apr 11, 2008 at 4:45 PM, Galchin, Vasili <[EMAIL PROTECTED]>
wrote:

> Right I am just trying to rebuild the unix package. No matter what version
> is present in the unix.cabal file,
>
> runhaskell Setup.hs configure
>
> produces an error concerning unix-2.3.0.0
>

Have you tried doing a 'runhaskell Setup.hs clean' first?  You should also
try unregistering the unix-2.3 package (ghc-pkg unregister unix-2.3.0.0).


>
> Starting to get really frustrated over this. I just want to build a Unix
> package test case .. and now I can't even build the unix package itself.
>
>  ghc-pkg seems to be at the center of this problem because the problem
> seems to have to deal with the package database.
>
> 1) On Linux(Ubuntu) where is the package database?
>

The global package database should be somewhere like

/usr/lib/ghc-6.6.1/package.conf

on my system it is in /usr/local/lib/ghc-6.8.2/package.conf.

The local (user) package database is in something like
~/.ghc/i386-linux-version/package.conf.


> 2) If ghc-pkg is indeed a Haskell program, how can I get the source to
> better understand the problem I am encountering on my own?
>

It is part of the ghc source, in utils/ghc-pkg.

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


Re[3]: [Haskell-cafe] ANNOUNCE: Generic Haskell 1.80 (Emerald)

2008-04-12 Thread Bulat Ziganshin
Hello Bulat,

Saturday, April 12, 2008, 6:10:04 PM, you wrote:

> it's an overview of generic haskell programming systems:

found longer paper myself:

Comparing Approaches to Generic Programming in Haskell
http://www.cs.uu.nl/~johanj/publications/ComparingGP.pdf



-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


Re[2]: [Haskell-cafe] ANNOUNCE: Generic Haskell 1.80 (Emerald)

2008-04-12 Thread Bulat Ziganshin
Hello Miguel,

Saturday, April 12, 2008, 5:54:45 PM, you wrote:
> How come I haven't ever heard about such a thing?!

it's an overview of generic haskell programming systems:
http://dfa.imn.htwk-leipzig.de/~waldmann/draft/meta-haskell/second.pdf

ask here about final version of this paper

-- 
Best regards,
 Bulatmailto:[EMAIL PROTECTED]

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


[Haskell-cafe] help understanding pj-lester-book

2008-04-12 Thread minh thu
Hi!

I don't understand something in there :

pj-lester-book :
Implementing functional languages: a tutorial
by Simon Peyton Jones and David Lester,
available at http://research.microsoft.com/~simonpj/Papers/pj-lester-book/

eval/apply :
Making a Fast Curry: Push/Enter vs. Eval/Apply for Higher-order Languages
by Simon Marlow and Simon Peyton Jones,
available at http://www.haskell.org/~simonmar/papers/

The introduction in eval/apply states the arity of a function and the
number of arguments in a call can match or differs (and it should be
dealt with).

In pj-lester-book (bottom of page 46 and top of page 47), it is stated
that if the program has been type-cheched, the underflow check is
unnecessary.
When continuing to the G-machine then to the TIM-machine chapters, I
haven't found discussion of an arity-mismatch.

What am I missing ?

Thanks a lot,
Thu
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANNOUNCE: Generic Haskell 1.80 (Emerald)

2008-04-12 Thread Miguel Mitrofanov

Generic Haskell includes the following features:

* type-indexed values -- generic functions that can be
  instantiated on all Haskell data types.


How come I haven't ever heard about such a thing?!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANNOUNCE: Generic Haskell 1.80 (Emerald)

2008-04-12 Thread Pablo Nogueira
On 12/04/2008, Thomas van Noort <[EMAIL PROTECTED]> wrote:

>  Generic Haskell includes the following features:
>
>  * type-indexed values -- generic functions that can be
>instantiated on all Haskell data types.
   ^^^

I have perused the manual and wonder if parametric types with class
constraints are now supported or are not considered Haskell types. I'm
thinking of types such as

data Ord a => BinTree a = Leaf | Node a (BinTree a) (BinTree a)
data Functor f => GRose f a = GLeaf | GNode a (f(GTree f a))
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ANNOUNCE: Generic Haskell 1.80 (Emerald)

2008-04-12 Thread Thomas van Noort
 Generic Haskell version 1.80 (Emerald)
 ==

We are happy to announce the fifth release of Generic Haskell,
an extension of Haskell that facilitates generic programming.

Generic Haskell includes the following features:

* type-indexed values -- generic functions that can be
   instantiated on all Haskell data types.

* type-indexed types -- types which are indexed over the type
   constructors underlying Haskell datatypes.

The Generic Haskell compiler takes Generic Haskell source
and produces Haskell code.


Changes since 1.62 (Diamond)


* Generic views for generic types [1] are now supported.

* The implementation of type-indexed types is improved.


Download


The Generic Haskell compiler is available in source and binary
distributions. Binaries for Linux, Windows, and MacOSX
are available. These are available from:

 http://www.generic-haskell.org/compiler.html

The documentation is also available separately from that page.

For more general information, point your browser to:

 http://www.generic-haskell.org


Why Generic Haskell?


Software development often consists of designing datatypes, around which
functionality is added.  Some functionality is datatype
specific, whereas other functionality is defined on almost all
datatypes in such a way that it depends only on the structure of the
datatype.  A function that works on many datatypes in this way
is called a generic function.  Examples of generic functionality
include editing, pretty-printing or storing a value in a database, and
comparing two values for equality.

Since datatypes often change and new datatypes are introduced, we
have developed Generic Haskell, an extension of the functional
programming language Haskell that supports generic definitions,
to save the programmer from (re)writing instances of generic
functions. The original design of Generic Haskell is based on work by Ralf
Hinze.

   Pleasant programming,
   The Generic Haskell Team at Utrecht University

   [EMAIL PROTECTED]

[1] Thomas van Noort. Generic views for generic types. Master's thesis,
Utrecht University, 2008.

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


Re: [Haskell-cafe] Re: Type families and GADTs in 6.9

2008-04-12 Thread Dan Doel
On Saturday 12 April 2008, ChrisK wrote:
> The length calculation looked complicated.  So I reformulated it as a
> comparison using HasIndex.  But ghc-6.8.2 was not inferring the recursive
> constraint on proj, so I split proj into proj_unsafe without the constraint
> and proj with the constraint checked only once.  I also renamed ZT to Nil
> to be more consistent.

Ah, well, in fact, you can also structure things this way:

--

data Tuple ts n where
  Nil   :: Tuple Nil Zero
  (:::) :: t -> Tuple ts n -> Tuple (t ::: ts) (Succ n)

proj :: Fin fn n -> Tuple ts n -> Lookup ts fn
-- proj is the same as my original mail

--

That ensures that a tuple of size n is indexed by the finite set of size n. 
The two are a natural fit for one another, since there are as many elements 
in the tuple as there are in the finite set. This actually works on 6.8.2 
(modulo having to tell GHCi what result type it ought to get in some cases, 
since it thinks there is no Show instance for Lookup (Int ::: Nil) FZ :)), 
and gives type errors if you try to do, say 'proj f2 ('a' ::: 'b' ::: Nil)': 

  f2:: Fin (FS (FS FZ)) (Succ (Succ (Succ n)))
  tuple :: Tuple (Char ::: Char ::: Nil) (Succ (Succ Zero))
   => Succ (Succ (Succ n)) ~ Succ (Succ Zero) -- no can do

My main confusion was that none of this works in 6.9, seemingly because the 
pattern match against FZ in proj fails to refine the type variable fn to FZ, 
which is necessary to solve the equation 't ~ Lookup (t ::: ts) fn', so 
instead it tells me I'm asking for an infinite type.

However, the type checker not figuring out that Succ n ~ Length (t ::: ts) 
implies that n ~ Length ts in the recursive call is, I think, the problem I 
was having with the original alternate signature. I suppose it's less trivial 
than HasIndex, but you say it didn't like that either. It'd be interesting to 
know if that sort of thing will be possible in 6.10, or if it's unreasonable 
to expect that to work.

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


[Haskell-cafe] Re: Type families and GADTs in 6.9

2008-04-12 Thread ChrisK
The length calculation looked complicated.  So I reformulated it as a comparison 
using HasIndex.  But ghc-6.8.2 was not inferring the recursive constraint on 
proj, so I split proj into proj_unsafe without the constraint and proj with the 
constraint checked only once.  I also renamed ZT to Nil to be more consistent.



-- works in ghc 6.8.2
{-# LANGUAGE GADTs, TypeFamilies, EmptyDataDecls, TypeOperators #-}

data FZ
data FS a

data Fin fn where
  FZ :: Fin FZ
  FS :: Fin fn -> Fin (FS fn)

f0 = FZ
f1 = FS f0
f2 = FS f1
-- ... etc.

data Nil
data t ::: ts

infixr 4 :::

data Tuple ts where
  Nil:: Tuple Nil
  (:::) :: t -> !(Tuple ts) -> Tuple (t ::: ts)

data HTrue

type family Lookup ts fn :: *
type instance Lookup (t ::: ts) FZ = t
type instance Lookup (t ::: ts) (FS fn) = Lookup ts fn

type family HasIndex ts fn :: *
type instance HasIndex (t ::: ts) FZ = HTrue
type instance HasIndex (t ::: ts) (FS fn) = HasIndex ts fn

{-# INLINE proj #-}
proj :: (HasIndex tsT fnT ~ HTrue) => Fin fnT -> Tuple tsT -> Lookup tsT fnT
proj = proj_unsafe  where
  proj_unsafe :: Fin fnT -> Tuple tsT -> Lookup tsT fnT
  proj_unsafe (FS fn) (_v ::: vs) = proj_unsafe fn vs
  proj_unsafe FZ  (v ::: _vs) = v
  proj_unsafe _   Nil = error "Cannot proj Nil in proj_unsafe"

fst' :: (HasIndex ts FZ ~ HTrue) => Tuple ts -> Lookup ts FZ
fst' = proj f0

snd' :: (HasIndex ts (FS FZ) ~ HTrue) => Tuple ts -> Lookup ts (FS FZ)
snd' = proj f1

pair :: Tuple (Char ::: (() ::: Nil))
pair = 'a' ::: () ::: Nil

q1 :: Char
q1 = fst' pair

q2 :: ()
q2 = snd' pair

{- This won't compile

q2 :: ()
q2 = snd' ('a' ::: Nil)
-}



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


Re: [Haskell-cafe] do construct in wxhaskell

2008-04-12 Thread Abhay Parvate
The indentation is not right; all the statements after the 'do' keyword need
to start exactly at the same column. In particular, the 'f' in fileContent
and 's' in set should be one below the other. And the 'return ()' also seems
to be displaced; perhaps you want that also exactly below the last 'set' if
it's the part of the last case.

Hope it helps
Abhay

2008/4/12 Jodi-Ann Prince <[EMAIL PROTECTED]>:

>  hi, im working ona project, and im having problem loading some code in
> wxhaskell:
>
>
> onOpen :: Frame a -> TextCtrl b -> MenuItem c -> StatusField -> IO ()
> onOpen f sw mclose status = do   mbfname <- fileOpenDialog f False True
> "Open image" fileTypes "" ""
>   case  (mbfname) of
>   (Nothing)  -> return ()
>   (Just (fname)) -> do
> fileContent <- readFile fname
>
> set sw [text := fileContent]
>
> set mclose [enabled := True]
>
> set status [text := fname]
>   return ()
>
> i keep getting the error : "the last statement in a 'do' construct must be
> an expression."
> ive tried rearranging it many times, but i still get the same error. any
> help would be greatly appreciated.
>
> --
> Connect to the next generation of MSN Messenger  Get it now!
> 
>
> ___
> 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