GHCI segfault on Double math

2012-12-07 Thread Ron Alford
I'm trying to see if this is reproducible, or it's just my machine.
I'm on a MacBook Pro (15-inch, Mid 2012), OS X 10.8.2, Haskell Platform
2012.4.0.0 (32 bit):

$ ghci
GHCi, version 7.4.2: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude properFraction (-1.1 :: Float)
(-1,-0.10024)
Prelude properFraction (1.1 :: Double)
(1,0.10009)
Prelude properFraction (-1.1 :: Double)
(-1,Segmentation fault: 11

'ceiling' and other code that uses properFraction segfaults on negative
doubles, too.

Compiled code doesn't have this defect.  I'm going to try the 64 bit
version to see if it resolves this problem.


-Ron Alford
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: More infinite simplifier bugs?

2012-07-06 Thread Ron Alford
On Fri, Jul 6, 2012 at 7:18 AM, Simon Peyton-Jones
simo...@microsoft.com wrote:
 try with -ddump-rule-firings -dverbose-core2core -ddump-occur-anal 
 -ddump-inlinings.

 You'll get a lot of output ,but you may either see (a) output stops but 
 computer gets hot, (b) output goes on and on.

 use HEAD if you can


Thanks.  I haven't set HEAD up yet, but for 7.4.2, (b) appears to be
the case (the function pddlDocExpr appears in the output quite often).
I'm still trying to whittle down my program to a small test case, but
even small and seemingly irrelevant changes are enough to restore
GHC's termination.

-Ron Alford


ghcloop.hs
Description: Binary data
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


More infinite simplifier bugs?

2012-07-05 Thread Ron Alford
So a while back Simon added a tick counter to the simplifier:
http://hackage.haskell.org/trac/ghc/ticket/5448

Are there any known bugs that can cause the simplifier to run out of
memory /without/ hitting the tick counter limit?

I have code that /used/ to run (at least after hacking around the
previous simplifier bug):
https://github.com/ronwalf/Planning

With GHC 7.4.[12], it exhausts all the RAM on my machine (4GB).

Compiling with -O0 fixes the problem.  I can start bisecting my code
to find the problem if nothing comes to mind.

-Ron Alford
(who seems to be good at killing the simplifier)

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Inliner non-termination

2011-09-06 Thread Ron Alford
From the known bugs
(http://www.haskell.org/ghc/docs/latest/html/users_guide/bugs.html#bugs-ghc):
GHC's inliner can be persuaded into non-termination using the
standard way to encode recursion via a data type...
We have never found another class of programs, other than this
contrived one, that makes GHC diverge, and fixing the problem would
impose an extra overhead on every compilation. So the bug remains
un-fixed.

There are now three more examples, at least two of which weren't 'contrived':

http://hackage.haskell.org/trac/ghc/ticket/5448
http://hackage.haskell.org/trac/ghc/ticket/5400
http://hackage.haskell.org/trac/ghc/ticket/3872

It took me about 4-6 hours to track down this bug in my own code
(#5448) since it required repeatedly bisecting a larger program until
I had a small testcase.  In the test program, I can get around it with
{-# NOINLINE funcEq #-}.  In the program it came from, though, FuncEq
is an imported value, so I have to either compile with -O0, or change
put the pragma in the imported library, where it will effect a fair
amount of code that /doesn't/ hit this bug.


If adding the check is too expensive, can the inliner have a
configurable recursion bount (ala -fcontext-stack)?

-Ron Alford

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: Inliner non-termination

2011-09-06 Thread Ron Alford
On Tue, Sep 6, 2011 at 7:50 PM, Felipe Almeida Lessa
felipe.le...@gmail.com wrote:
 This doesn't solve GHC's bug, but can you do something like

  myFuncEq = funcEq
  {-# NOINLINE myFuncEq #-}

 and just use myFuncEq everywhere?  This should make the change local
 to your module.

Unfortunately not.  The only time I use funcEq in the code in question
is the instance declaration.

-Ron Alford

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: [Haskell-cafe] Re: How does one get off haskell?

2010-06-21 Thread Ron Alford
On Fri, Jun 18, 2010 at 10:30 AM, C. McCann c...@uptoisomorphism.net wrote:
 The better question is when do the benefits of static typing outweigh
 the costs imposed?. If you're using Java, the answer is probably
 never, but even in Haskell I don't think the answer is quite
 always.

I have half a concrete example!  I do research in automated planning,
and the standard problem definition language is PDDL[1].
PDDL uses FOL logic expressions for expressing goal conditions, action
preconditions, effects and various other things.  The problem comes in
that it uses a /different/ subset of first-order logic for each
expression, leading to something like 8 or so expression types
contained just in PDDL 3.1 (the latest 'standard').  Then there are
the many previous versions of PDDL, and all the many extensions and
subset/extensions to various versions of PDDL used in other people's
research projects.

So, when I wrote a PDDL library to help with my research, I needed
extensibility.   If not, I'd need to either fork the library for every
PDDL extension, or create some sort of uber-PDDL which contained all
the extensions.  The best I came up with is Wouter's Datatypes a la
Carte [2] which I used along with an extensible record technique my
implementation[3]*.

There are downsides to this approach.  The most obvious is that to
define a function over one of these datatypes, you need to define a
class associated with that function and then define an instance of
that class for every component.
Also, type signatures are huge and I feeling like I'm using half the
language extensions out there.  I end up with a full complement of
boilerplate code, and it doesn't even buy me full expression type
safety (there are restrictions in PDDL on how expressions combine).

Now, one thing I'm missing out of this example is the other side of
the coin - doing it better in a dynamically typed language.  However,
there are plenty of C, lisp, and python PDDL planners out there, and
I'm pretty sure they don't bother with type safe expressions.  Also,
this isn't an indictment of static typing in general.  This only shows
that my task isn't well suited to Haskell's current static typing.

-Ron Alford


* Note that this was my first and only real haskell project, and all
that this entails.

[1] http://en.wikipedia.org/wiki/Planning_Domain_Definition_Language
[2] http://lambda-the-ultimate.org/node/2700
[3] http://www.cs.umd.edu/projects/planning/data/alford09translating/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Interest in a Mathematics AI strike force ?

2010-05-05 Thread Ron Alford
On Wed, May 5, 2010 at 12:10 PM, Neal Alexander relapse@gmx.com wrote:
 - Goal Oriented Behaviors (work in progress)
 - Goal Oriented Planning (work in progress)

I have a library for PDDL parsing and representation[1] that I used in
a recent paper.  It's heavy complex types to deal with various
extensions to the language.  I'm currently updating it for another
project, so if you're interested, please let me know!

-Ron

[1] http://www.cs.umd.edu/projects/planning/data/alford09translating/
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Deriving regression or bad code?

2010-04-12 Thread Ron Alford
I was getting a similar error with standalone deriving (already
attached to that bug), but I didn't try it through-out.  I'll let you
know how it goes.

-Ron


On Mon, Apr 12, 2010 at 6:01 AM, Simon Peyton-Jones
simo...@microsoft.com wrote:
 It's really a bug. I've fixed it in my tree, but I'm at 2.8 and don't have 
 time to validate etc.  So I'm doubtful that I'll be in time to get a fix into 
 6.12.1, alas.

 Well, maybe I can build a patch and send it to Simon/Ian for testing. I'll 
 try to do that if it's important to you.

 it's bit of an exotic case because of the higher-kindedness so I don't think 
 it'll bite too man people

 There's a good workaround: use standalone deriving.

 You

 | -Original Message-
 | From: glasgow-haskell-users-boun...@haskell.org [mailto:glasgow-haskell-
 | users-boun...@haskell.org] On Behalf Of Ron Alford
 | Sent: 10 April 2010 22:33
 | To: glasgow-haskell-users
 | Subject: Re: Deriving regression or bad code?
 |
 | Just for fun, I tried it on 6.12.1.20100330 with the same result.
 | Does anyone have a workaround?  Otherwise I need to revert to 6.10.
 |
 | -Ron
 |
 | On Thu, Apr 8, 2010 at 10:35 AM, Ron Alford ronw...@volus.net wrote:
 |  At Igloo's suggestion, it's now a ticket:
 |  http://hackage.haskell.org/trac/ghc/ticket/3965
 | 
 |  -Ron
 | 
 |  On Thu, Apr 8, 2010 at 1:39 AM, Ron Alford ronw...@volus.net wrote:
 |  I've attached the simplest example of my code that used to compile in
 |  GHC 6.10 now gives the error in GHC 6.12.1:
 |  ...
 | 
 | ___
 | Glasgow-haskell-users mailing list
 | Glasgow-haskell-users@haskell.org
 | http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: Deriving regression or bad code?

2010-04-10 Thread Ron Alford
Just for fun, I tried it on 6.12.1.20100330 with the same result.
Does anyone have a workaround?  Otherwise I need to revert to 6.10.

-Ron

On Thu, Apr 8, 2010 at 10:35 AM, Ron Alford ronw...@volus.net wrote:
 At Igloo's suggestion, it's now a ticket:
 http://hackage.haskell.org/trac/ghc/ticket/3965

 -Ron

 On Thu, Apr 8, 2010 at 1:39 AM, Ron Alford ronw...@volus.net wrote:
 I've attached the simplest example of my code that used to compile in
 GHC 6.10 now gives the error in GHC 6.12.1:
 ...

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: Deriving regression or bad code?

2010-04-08 Thread Ron Alford
At Igloo's suggestion, it's now a ticket:
http://hackage.haskell.org/trac/ghc/ticket/3965

-Ron

On Thu, Apr 8, 2010 at 1:39 AM, Ron Alford ronw...@volus.net wrote:
 I've attached the simplest example of my code that used to compile in
 GHC 6.10 now gives the error in GHC 6.12.1:
...
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Deriving regression or bad code?

2010-04-07 Thread Ron Alford
I've attached the simplest example of my code that used to compile in
GHC 6.10 now gives the error in GHC 6.12.1:
baddata.hs:33:14:
No instances for (Data Const, Data Var)
  arising from the 'deriving' clause of a data type declaration
   at baddata.hs:33:14-17
Possible fix:
  add an instance declaration for (Data Const, Data Var)
  or use a standalone 'deriving instance' declaration instead,
 so you can specify the instance context yourself
When deriving the instance for (Data (Domain e g))

If I replace:
 data Domain e g = Domain
 (Expr (Const :+: Var))
 deriving (Data, Typeable)

with:
 data Domain e g = Domain
(Expr (Const))
deriving (Data, Typeable)

then everything compiles.  If nothing else, the error message is misleading.

-Ron


baddata.hs
Description: Binary data
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: [Haskell-cafe] GHC Error: FATAL:Symbol _XJv_srt already defined.

2008-08-14 Thread Ron Alford
I reopened the bug, since I found slight changes to the file were able
to reproduce the bug in recent versions of ghc-6.9.
I also can't get the -S compilation step to work with the new file,
unless I'm missing a step.

-Ron Alford

On Mon, Jul 21, 2008 at 3:32 AM, Ron Alford [EMAIL PROTECTED] wrote:
 Oops, already posted the bug:
 http://hackage.haskell.org/trac/ghc/ticket/2456

 On Mon, Jul 21, 2008 at 3:29 AM, Austin Seipp [EMAIL PROTECTED] wrote:
 Status update: after checking out the latest HEAD and building it, the
 above error does not occur:

 $ ~/ghc-head/bin/ghc --version
 The Glorious Glasgow Haskell Compilation System, version 6.9.20080720
 $ ~/ghc-head/bin/ghc --make DerivingError.hs

 no location info:
Warning: -fallow-overlapping-instances is deprecated: Use the
OverlappingInstances language instead
 [1 of 1] Compiling DerivingError( DerivingError.hs, DerivingError.o )
 $

 However, this doesn't exactly help your immediate problem, and it
 likely won't until 6.10.1 is released, as 6.8.3 is going to be the
 last release of the 6.8 branch.

 Truly sorry I couldn't have helped you more.

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


GHC Error: FATAL:Symbol _XJv_srt already defined.

2008-07-20 Thread Ron Alford
I posted this to Haskell-Cafe, but it's more GHC specific.

Anyone know what this is about? Removing parts makes problem go away,
but it's not clear what parts to remove! (that, and I wrote those
parts for a reason!).

bash-3.2$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.8.3
bash-3.2$ uname -a
Darwin silverback-wired.home 9.4.0 Darwin Kernel Version 9.4.0: Mon
Jun  9 19:30:53 PDT 2008; root:xnu-1228.5.20~1/RELEASE_I386 i386


$ rm -f DerivingError.o DerivingError.hi; ghc --make DerivingError.hs
[1 of 1] Compiling DerivingError( DerivingError.hs, DerivingError.o )

/var/folders/C0/C0SledGV2RaxbU+8ZLDnVU+++TI/-Tmp-//ghc27223_0/ghc27223_0.s:6080:0:
   FATAL:Symbol _XxG_srt already defined.


-Ron Alford


DerivingError.hs
Description: Binary data
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


[Haskell-cafe] GHC Error: FATAL:Symbol _XJv_srt already defined.

2008-07-20 Thread Ron Alford
Anyone know what this is about? Removing parts makes problem go away,
but it's not clear what parts to remove! (that, and I wrote those
parts for a reason!).

bash-3.2$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.8.3
bash-3.2$ uname -a
Darwin silverback-wired.home 9.4.0 Darwin Kernel Version 9.4.0: Mon
Jun  9 19:30:53 PDT 2008; root:xnu-1228.5.20~1/RELEASE_I386 i386


$ rm -f DerivingError.o DerivingError.hi; ghc --make DerivingError.hs
[1 of 1] Compiling DerivingError( DerivingError.hs, DerivingError.o )

/var/folders/C0/C0SledGV2RaxbU+8ZLDnVU+++TI/-Tmp-//ghc27223_0/ghc27223_0.s:6080:0:
FATAL:Symbol _XxG_srt already defined.


-Ron Alford


DerivingError.hs
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Typeable and fancy types

2008-07-11 Thread Ron Alford
Hey all,
I've reduced my previous problem to a small example. Anyone know why
typeOf (...) would work, but typeOf [...] would not?  Is the
derivation for lists funky?

data Expr f = In (f (Expr f))
instance Typeable1 f = Typeable (Expr f) where
typeOf (In x) = mkTyConApp (mkTyCon TypeTest.Expr) [typeOf1 x]

data Foo e = Foo
deriving instance Typeable1 Foo

*TypeTest typeOf (In Foo)
TypeTest.Expr TypeTest.Foo
*TypeTest typeOf [In Foo]
*** Exception: Prelude.undefined


TypeTest.hs
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Combining Wouter's expressions with extensible records

2008-07-11 Thread Ron Alford
On Fri, Jul 11, 2008 at 12:50 PM, Antoine Latter [EMAIL PROTECTED] wrote:

 Now we never do pattern matching on our input.

 This has been pretty educational.


Mightily! I'll have to do the same trick for Expr.

Thank you very much!
-Ron
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Combining Wouter's expressions with extensible records

2008-07-10 Thread Ron Alford
On Wed, Jul 9, 2008 at 11:01 PM, Antoine Latter [EMAIL PROTECTED] wrote:

 It isn't immediately obvious to me that the Typeable family of
 classes deal at all with higher-kinded type constructors, but I didn't
 look that hard.


Yes, that's what I'm worried about.  For people's fun and amusement,
I've attached the file.  The trailing comments show what I'm trying to
accomplish (getName, setName, and so forth).

-Ron


WouterTest.hs
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Combining Wouter's expressions with extensible records

2008-07-10 Thread Ron Alford
Or, if people have easy-enough extensible records that /will/ work
with funky types, I'd be happy to use those!

-Ron

On Thu, Jul 10, 2008 at 10:29 AM, Ron Alford [EMAIL PROTECTED] wrote:
 On Wed, Jul 9, 2008 at 11:01 PM, Antoine Latter [EMAIL PROTECTED] wrote:

 It isn't immediately obvious to me that the Typeable family of
 classes deal at all with higher-kinded type constructors, but I didn't
 look that hard.


 Yes, that's what I'm worried about.  For people's fun and amusement,
 I've attached the file.  The trailing comments show what I'm trying to
 accomplish (getName, setName, and so forth).

 -Ron

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


[Haskell-cafe] Data.Derive problems

2008-07-10 Thread Ron Alford
I'm using GHC 6.8.3 with $ cabal --version
cabal-install version 0.5.1
using version 1.4.0.1 of the Cabal library

I installed Data.Derive from hackage, only to be unable to find the
'derive' binary!

Trying it directly from darcs, I get:
$ ghc --make Setup.hs
[1 of 1] Compiling Main ( Setup.hs, Setup.o )
Linking Setup ...
silverback-wired:derive ronwalf$ ./Setup configure
Warning: defaultUserHooks in Setup script is deprecated.
Configuring derive-0.1.1...
Warning: No 'build-type' specified. If you do not need a custom Setup.hs or
./configure script then use 'build-type: Simple'.


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


[Haskell-cafe] Re: Combining Wouter's expressions with extensible records

2008-07-10 Thread Ron Alford
I'm making progress, but how would I make the following a Typeable instance:
data (f :+: g) e = Inl (f e) | Inr (g e) deriving Eq

Here is what I'm using for Expr:
data Expr f = In (f (Expr f))
instance Typeable1 f = Typeable (Expr f) where
typeOf (In x) = mkTyConApp (mkTyCon Data.Trie.General.ListGT) [typeOf1 x]

I don't think I can use this for ':+:', because the typeOf instance
only has access to a member of one type at a time.
This may be similar to a definition of Typeable2 for Either, but I
can't find an example to follow for that.

Thanks,
-Ron

On Wed, Jul 9, 2008 at 10:40 PM, Ron Alford [EMAIL PROTECTED] wrote:
 Well, my extension of Wouter's datatypes proved to be unweildy
 So, I'm trying to use
 http://fmapfixreturn.wordpress.com/2008/05/03/simple-extensible-records-now-quick-generic-tricks-pt-1/
 for extensible records.

 I ran across my first problem rather quickly!
 data Expr f = In (f (Expr f))

 Ok, but to make it part of a record, it needs to implement Data:
 data Expr f = In (f (Expr f)) deriving Data

 but this gives
No instances for (Data (f (Expr f)), Typeable (Expr f))
  arising from the 'deriving' clause of a data type declaration
   at Planning/Wouter.hs:77:0-42

 Any hints?

 Thanks,
 -Ron

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


Re: [Haskell-cafe] Data.Derive problems

2008-07-10 Thread Ron Alford
On Thu, Jul 10, 2008 at 3:18 PM, Neil Mitchell [EMAIL PROTECTED] wrote:
 Hi Ron,

 I'm using GHC 6.8.3 with $ cabal --version
  cabal-install version 0.5.1
  using version 1.4.0.1 of the Cabal library

  I installed Data.Derive from hackage, only to be unable to find the
  'derive' binary!

 Did you do the runhaskell Setup configure  runhaskell Setup build 
 runhaskell Setup install?

I used 'sudo cabal install derive'.  I did find the binary - in my
user's .cabal/bin directory!  Odd that it should default to that when
run as root.

I don't have the darcs version working yet, though.

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


Re: [Haskell-cafe] Re: Combining Wouter's expressions with extensible records

2008-07-10 Thread Ron Alford
Close - it compiles now!  I made a minor change, going to Typeable1
instead of Typeable:

instance (Typeable1 f, Typeable1 g) = Typeable1 (f :+: g) where
typeOf1 l@(Inl x) = mkTyConApp (mkTyCon Planning.Wouter.:+:)
[typeOf1 x, typeOf1 y]
where (Inr y) = undefined `asTypeOf` l
typeOf1 r@(Inr y) = mkTyConApp (mkTyCon Planning.Wouter.:+:)
[typeOf1 x, typeOf1 y]
where (Inl x) = undefined `asTypeOf` r

Except this gives me a runtime error:
*WouterTest getName testNamed
*** Exception: Prelude.undefined

The only thing I can think of is to have a class that gives default
values to type - ick!

-Ron Alford

On Thu, Jul 10, 2008 at 4:16 PM, Antoine Latter [EMAIL PROTECTED] wrote:
 On Thu, Jul 10, 2008 at 2:15 PM, Ron Alford [EMAIL PROTECTED] wrote:
 I'm making progress, but how would I make the following a Typeable instance:
 data (f :+: g) e = Inl (f e) | Inr (g e) deriving Eq

 Here is what I'm using for Expr:
 data Expr f = In (f (Expr f))
 instance Typeable1 f = Typeable (Expr f) where
typeOf (In x) = mkTyConApp (mkTyCon Data.Trie.General.ListGT) [typeOf1 
 x]

 I don't think I can use this for ':+:', because the typeOf instance
 only has access to a member of one type at a time.
 This may be similar to a definition of Typeable2 for Either, but I
 can't find an example to follow for that.


 Maybe something like:

 instance (Typeable1 f, Typeable1 g) = Typeable (f :+: g) where
  typeOf in@(InL f) = (some function of 'f' and 'g')
where  InR g = undefined `asTypeOf` in

  typeOf in@(InR g) = (some function of 'f' and 'g')
where InL f = undefined `asTypeOf` in

 would work?

 -Antoine



WouterTest.hs
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Combining Wouter's expressions with extensible records

2008-07-10 Thread Ron Alford
This is a bit similar to Either.  Is there a way to see the generated
instance code for
deriving instance Data Either ?

On Thu, Jul 10, 2008 at 6:38 PM, Ron Alford [EMAIL PROTECTED] wrote:
 Close - it compiles now!  I made a minor change, going to Typeable1
 instead of Typeable:

 instance (Typeable1 f, Typeable1 g) = Typeable1 (f :+: g) where
typeOf1 l@(Inl x) = mkTyConApp (mkTyCon Planning.Wouter.:+:)
 [typeOf1 x, typeOf1 y]
where (Inr y) = undefined `asTypeOf` l
typeOf1 r@(Inr y) = mkTyConApp (mkTyCon Planning.Wouter.:+:)
 [typeOf1 x, typeOf1 y]
where (Inl x) = undefined `asTypeOf` r

 Except this gives me a runtime error:
 *WouterTest getName testNamed
 *** Exception: Prelude.undefined

 The only thing I can think of is to have a class that gives default
 values to type - ick!

 -Ron Alford

 On Thu, Jul 10, 2008 at 4:16 PM, Antoine Latter [EMAIL PROTECTED] wrote:
 On Thu, Jul 10, 2008 at 2:15 PM, Ron Alford [EMAIL PROTECTED] wrote:
 I'm making progress, but how would I make the following a Typeable instance:
 data (f :+: g) e = Inl (f e) | Inr (g e) deriving Eq

 Here is what I'm using for Expr:
 data Expr f = In (f (Expr f))
 instance Typeable1 f = Typeable (Expr f) where
typeOf (In x) = mkTyConApp (mkTyCon Data.Trie.General.ListGT) [typeOf1 
 x]

 I don't think I can use this for ':+:', because the typeOf instance
 only has access to a member of one type at a time.
 This may be similar to a definition of Typeable2 for Either, but I
 can't find an example to follow for that.


 Maybe something like:

 instance (Typeable1 f, Typeable1 g) = Typeable (f :+: g) where
  typeOf in@(InL f) = (some function of 'f' and 'g')
where  InR g = undefined `asTypeOf` in

  typeOf in@(InR g) = (some function of 'f' and 'g')
where InL f = undefined `asTypeOf` in

 would work?

 -Antoine


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


Re: [Haskell-cafe] Re: Combining Wouter's expressions with extensible records

2008-07-10 Thread Ron Alford
Ok, I'm closer, but I'm running into a problem with typeOf and lists,
of all things:
*WouterTest typeOf (eVar v :: TermExpr)
Planning.Wouter.Expr (Planning.Wouter.:+: WouterTest.Const WouterTest.Var)
*WouterTest typeOf ([eVar v] :: [TermExpr])
*** Exception: Prelude.undefined

I'm pretty sure this is the culprit for getName:
*WouterTest getName testNamed
*** Exception: Prelude.undefined

Any hints?

Also, anyone have hints for how to get automatic derivation of Data (Expr f) ?
I don't want to proliferate the last lines:
deriving instance Data (Expr (And :+: Atomic (Expr (Const :+: Var
deriving instance Data (Expr (Const :+: Var))


-Ron Alford


WouterTest.hs
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Combining Wouter's expressions with extensible records

2008-07-09 Thread Ron Alford
Well, my extension of Wouter's datatypes proved to be unweildy
So, I'm trying to use
http://fmapfixreturn.wordpress.com/2008/05/03/simple-extensible-records-now-quick-generic-tricks-pt-1/
for extensible records.

I ran across my first problem rather quickly!
data Expr f = In (f (Expr f))

Ok, but to make it part of a record, it needs to implement Data:
data Expr f = In (f (Expr f)) deriving Data

but this gives
No instances for (Data (f (Expr f)), Typeable (Expr f))
  arising from the 'deriving' clause of a data type declaration
   at Planning/Wouter.hs:77:0-42

Any hints?

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


[Haskell-cafe] Wouter Swierstra style extensible records!

2008-07-03 Thread Ron Alford
Having made over-use of Wouter's expression idioms, I decided to hack
it into extensible records.
It's not documented, it's probably got holes in its usability, but I
thought I'd post it so people can play with it (and give suggestions
before I rewrite my code to use it!).

I know there are other extensible record systems, but I wondered how
this stacks up.  Notably, it looks like in HList the records are only
extensible in one direction (tacking fields onto the end), although
they have a much more developed syntax (if you're into that sort of
thing).

Current problems:
* Defining a new field is rather bulky - currently it takes lines.
Definitions are bulky in Wouter's extensible expressions, too, but I
could probably shorten the get/set convenience functions to something
more readable.
* Construction of new records is only convenient by using the
defaulting system.  Maybe that makes sense, maybe it doesn't.

A side benefit:
Record access functions are reusable between record types (as long as
they have the same type).

Anyway, thanks again, Wouter!

-Ron


WouterRecords.hs
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell's type system

2008-06-17 Thread Ron Alford
I'm trying to wrap my head around the theoretical aspects of haskell's
type system. Is there a discussion of the topic separate from the
language itself?

Since I come from a rather logic-y background, I have this
(far-fetched) hope that there is a translation from haskell's type
syntax to first order logic (or an extension there-of).  Is this done?
 Doable?

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


[Haskell-cafe] Wouter-style expressions

2008-06-04 Thread Ron Alford
Here's something that should be an easy extension of Wouter's approach
to extensible datatypes, but I'm failing (possibly since it's 2:20am).
 I several classes of expressions I'm trying to represent (thus,
Wouter's approach), and  my first operation to implement over them is
printing.

Attached is a simplified version of what I'm doing.  Expressions are
composed of conjunctives (and) and atoms.  Atoms are composed of a
predicate string and a list of fillers (taken from 'Const' and 'Var').
 For example (in a lisp like syntax):
(and (pred c ?var1) (pred ?var1 ?var2))

To do this, I defined a 'Printable' class:
class Functor f = Printable f where
exprDoc :: f t - Doc

I think the 't' here will get me into trouble later.

Combinations of printable types are also printable:
instance (Printable f, Printable g) = Printable (f :+: g) where
exprDoc (Inr x) = exprDoc x
exprDoc (Inl y) = exprDoc y


Constants, variables, and atoms are defined to be printable:
instance Printable Var where
exprDoc (Var name) = text ('?':name)

instance Printable Const where
exprDoc (Const name) = text name

instance Printable f = Printable (Atomic (Expr f)) where
exprDoc (Atomic p tl) = parens $ hsep $
(text p) : (map (\ (In t) - exprDoc t) tl)

But the obvious definition for conjunction doesn't work:
instance Printable And where
exprDoc (And el) = sep (map exprDoc el)

GHC barfs, throwing:
Couldn't match expected type `f t' against inferred type `t1'
  `t1' is a rigid type variable bound by
   the type signature for `exprDoc' at WouterTest.hs:62:17
  Expected type: [f t]
  Inferred type: [t1]
In the second argument of `map', namely `el'
In the first argument of `sep', namely `(map exprDoc el)'


I've attached the code.  Compile and inspect with:
$ ghci -fglasgow-exts -fallow-overlapping-instances WouterTest.hs

test1 works great (other than needing some redundant typing, any hints?).

test2 needs the definition of 'Printable And' to print, but I haven't
gotten that to work yet.  It also needs the redundant typing.


-Ron

However, I tried making more complex expression (conjunction, in this
case), but I can't get the types to align.  In particular, if I
uncomment the obvious definition


WouterTest.hs
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Mutually recursive types?

2008-04-16 Thread Ron Alford
Here's the setup:
I have a series of problems that use various logical connectives.  The
problem is that they're not all the same.  So instead of creating one
giant datatype (or duplicating much code), I'd like to assemble them
like toy blocks.

I've boiled down an example here:

data LogicalConnective a =
Not a
| And [a]
| Or [a]

data BasicGoal a =
Atomic String [Term]
| Empty
| Logical (LogicalConnective a)
deriving (Show, Eq)

data PreferenceGoal1 =
Basic1 PreferenceGoal1
| Prefer1 PreferenceGoal1

This works OK, but PreferenceGoal1 is a dead end.  I can't combine it
with other connectives.  So I try:

data PreferenceGoal2 a =
Basic2  (PreferenceGoal2 a)
| Prefer2 (PreferenceGoal2 a)

And this works fine, but seems impossible to explicitly type (ie,
there is nothing to substitute for 'a' in a type declaration).  Or am
I wrong?

Also, it could be that this is just an ugly way to represent things
(it does require a huge number of constructors).  Any suggestions?

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