dynamics on polymorphic datatype

2003-07-25 Thread Wang Meng
Hi All,

I am trying to perform dynamic casting on polymorphic types.
Let's say I have a data type like:

> data Foo a = Foo a

Is there any way to use dynamics to convert a value of type Foo a to a
type reprentation? I try to use the toDyn in the dynamic libray, it
complains for ambigours a. Is there a solution to it?

Thank you very much.


 -W-M-
  @ @
   |
  \_/


___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


Re: StrategyLib - need help

2003-07-25 Thread Ralf Laemmel
(Let's go to haskell-cafe if we want to continue.)

Hi Dmitry,

Sigh. Indeed, the distributed instance Show TermRep is not fit.
The default TermRep in the Strafunski distribution is not even
willing to disclose constructor names. So there is no way unless
you tweak TermRep (and DrIFT). TermRep should hold a string component
for the constructor (or the string representation in the case of
primitive types).

I will provide a StrategyLib on top of Data.Generics very soon.
Then your trouble is gone.
(The "Scrap Your Boilerplate" approach is really much more convenient.)

As a quick fix, 
I advise you to code a monster switch as follows.
(Tested in StrategyLib/examples/little-lambda)


testShow:: [String]
testShow = runIdentity
(applyTU (full_tdTU myShowTU) expr4)
 where
  myShowTU = constTU []
 `adhocTU` (\(x::Expr)-> return [show x])
 `adhocTU` (\(x::Type)-> return [show x])
 `adhocTU` (\(x::Identifier)-> return [show x])


So this is one line per type. Not that bad.
And it is nice because you can comment out types easily
during debugging.

Greetings,
Ralf

>  RL> a) Add a class constraint for Show to the Term class.
>  RL>(Would that work? It's a bit invasive anyway.)
> Yes, that a bit invasive to say at least. With equal "ease" I can hack
> DrIFT to produce instances of Show the way I want them.
> 
>  RL> b) Alternatively, imoort TermRep and use explode and then show on
>  RL>TermRep. (This show maybe does not look so nice,
>  RL> but this should be good enough for debugging.)
> I dont quite follow you here. If I (show . explode) the topmost Term, I got
> just the name of the type of that term. If I try to build a traversal which
> "explode"-s everything on the way, I got the same error as before (which is
> expected, I believe).
> 
>  RL> c) Be more specific about what terms to print,
>  RL>say have type-specific cases for types of terms of interest. (This
>  RL>would be reasonable if you only care about a few types,
>  RL> or there are even just a few types anyway.)
> Thing is that there is a lot of types and I'd like to print all of them.
> 
> --
> Dmitry Astapov //ADEpt
> GPG KeyID/fprint: F5D7639D/CA36 E6C4 815D 434D 0498  2B08 7867 4860 F5D7 639D
> ___
> Haskell mailing list
> [EMAIL PROTECTED]
> http://www.haskell.org/mailman/listinfo/haskell

-- 
Ralf Laemmel
VU & CWI, Amsterdam, The Netherlands
http://www.cs.vu.nl/~ralf/
http://www.cwi.nl/~ralf/
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


Re: StrategyLib - need help

2003-07-25 Thread Dmitry Astapov

Evening, Ralf. 

Ralf Laemmel <[EMAIL PROTECTED]> 20:27 24/7/2003 wrote:

 RL> a) Add a class constraint for Show to the Term class.
 RL>(Would that work? It's a bit invasive anyway.)
Yes, that a bit invasive to say at least. With equal "ease" I can hack
DrIFT to produce instances of Show the way I want them.

 RL> b) Alternatively, imoort TermRep and use explode and then show on
 RL>TermRep. (This show maybe does not look so nice,
 RL> but this should be good enough for debugging.)
I dont quite follow you here. If I (show . explode) the topmost Term, I got
just the name of the type of that term. If I try to build a traversal which
"explode"-s everything on the way, I got the same error as before (which is
expected, I believe). 

 RL> c) Be more specific about what terms to print,
 RL>say have type-specific cases for types of terms of interest. (This
 RL>would be reasonable if you only care about a few types,
 RL> or there are even just a few types anyway.)
Thing is that there is a lot of types and I'd like to print all of them.


-- 
Dmitry Astapov //ADEpt
GPG KeyID/fprint: F5D7639D/CA36 E6C4 815D 434D 0498  2B08 7867 4860 F5D7 639D
___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell


Re: Function composition and currying

2003-07-25 Thread Dr Mark H Phillips
Thanks to all the people who responded to my question!

The solution from Wolfgang Jeltsch:

  (f.).g

was what I was after.  But the other responses were
useful also.

Thanks!

Mark.

On Thu, 2003-07-17 at 09:57, Dr Mark H Phillips wrote:
> Hi,
> 
> Hopefully this is a simple question.  I am wanting to know good ways
> of using ".", the function composition operator, when dealing with
> currying functions.
> 
> Suppose I have the following functions defined:
> 
>   f :: Int -> Int
>   f x = x*x
> 
>   g :: Int -> Int -> Int
>   g a b = a + b
> 
> If I wish to add 1 and 2 together and then square them I can do:
> 
>   f (g 1 2) = 9
> 
> but what if I wish to use function composition in the process?
> 
> I can't do 
> 
>   (f.g) 1 2
> 
> because the 2 doesn't get passed in till too late.
> 
> I could do
> 
>   (f.(g 1)) 2
> 
> or even
> 
>   (f.(uncurry g)) (1,2)
> 
> But what I really want is a function with signature Int -> Int -> Int.
> The answer is probably:
> 
>   (curry (f.(uncurry g))) 1 2
> 
> but this seems awfully messy just to do f (g 1 2).
> 
> And what if g were a function with three curried arguments?  Then
> uncurry and curry wouldn't apply.  What then?
> 
> Is there a better way?
> 
> Thanks,
> 
> Mark.
> 
> 
> -- 
> Dr Mark H Phillips
> Research Analyst (Mathematician)
> 
> AUSTRICS - smarter scheduling solutions - www.austrics.com
> 
> Level 2, 50 Pirie Street, Adelaide SA 5000, Australia
> Phone +61 8 8226 9850
> Fax   +61 8 8231 4821
> Email [EMAIL PROTECTED]
> 
> ___
> Haskell mailing list
> [EMAIL PROTECTED]
> http://www.haskell.org/mailman/listinfo/haskell
-- 
Dr Mark H Phillips
Research Analyst (Mathematician)

AUSTRICS - smarter scheduling solutions - www.austrics.com

Level 2, 50 Pirie Street, Adelaide SA 5000, Australia
Phone +61 8 8226 9850
Fax   +61 8 8231 4821
Email [EMAIL PROTECTED]

___
Haskell mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell