Re: [Haskell-cafe] Dynamically typing TH.Exp at runtime

2009-03-13 Thread Martin Hofmann
Sorry, maybe it I didn't made it clear enough.

 Perhaps I'm misunderstanding something, but since one can infer types
 in GHCI, that implies one can infer types in the GHC API; since Hint
 wraps the GHC API, that implies one can infer types in Hint, doesn't
 it? And indeed, there are functions to infer the type of a String;
 iirc I've even used them myself in mueval.
 
That's true, inferring the type of a string is not the problem. However,
I am not only interested in the top-level type, but also in the type of
any arbitrary subexpression. Consider for example following recursive
definition:

foo [] = []
foo (x:xs) = (:)(x+1)(foo xs)

Typing only the first rule one would says its type is '[a] - [a]'.
However, the second rule specialises the type to 'Num a = [a] - [a]'.
So, if I am interested in the type of the 'x' in the pattern of the
second rule, I need to be aware of its binding on the right-hand side.
Consequently the type of 'x' is 'Num a'.

AFAIK, I need Hendley-Milner type inference for that (please correct me
if I am wrong) and I was wondering if I really need to implement it by
myself, when it is already somewhere inside GHC.

Thanks,

Martin

   

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


Re: [Haskell-cafe] Dynamically typing TH.Exp at runtime

2009-03-13 Thread Brandon S. Allbery KF8NH

On 2009 Mar 13, at 4:03, Martin Hofmann wrote:
That's true, inferring the type of a string is not the problem.  
However,
I am not only interested in the top-level type, but also in the type  
of

any arbitrary subexpression. Consider for example following recursive
definition:


I'm pretty sure you can pull a typed AST out of ghc-api and query the  
type of any node.


--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com
system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu
electrical and computer engineering, carnegie mellon universityKF8NH




PGP.sig
Description: This is a digitally signed message part
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Dynamically typing TH.Exp at runtime

2009-03-12 Thread Martin Hofmann
I am doing meta-programming at runtime. So my program gets a full
Haskell declaration in expression quotation ([d|...|]) modifies it and
returns the modified expression. Therefore, I need type information of
this expression, and any subexpression, at _runtime_ !  For example:

[d| reverse x1 = y1 |]

  - rewrites_to -

[d| reverse x2:xs = y2:ys |]

  - rewrites_to -

[d| reverse x:xs = reverse xs ++  [x] |]

reverse :: [a] - [a] implies
x2,y2 :: a
x1,y1,xs,ys :: [a]

TH.reify is not applicable, because I need the information at runtime
and I am in IO. I suppose Data.Dynamic does not work either, because [|
xs|] :: ExpQ and not [a].

So it looks like I need my own type checker and inference and tag each
subexpression with its type. If so, I can even omit TH and use my own
data type for the abstract syntax tree. This annoys me a bit, because
for me it seems that all I need is already there.

Did anybody have similar problems, because I shouldn't be the only one
doing dynamic typing in a static language? Is there a Haskell
implementation of the paper Typing Dynamic Typing by Baars and
Swierstra (http://people.cs.uu.nl/arthurb/dynamic.html ), so I can try
out if this helps me?

Any help, comments, and how-to-suggestions are highly welcome.

Thanks a lot,

Martin



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


Re: [Haskell-cafe] Dynamically typing TH.Exp at runtime

2009-03-12 Thread Martin Hofmann
This is what hint does, isn't it? However, this still leaves it to me to
infer what type [|a|] in [| reverse (a:b:[]) = (b:a:[]) |] is. 

Thanks a lot anyway.

Martin

On Thu, 2009-03-12 at 12:59 -0200, Daniel GorĂ­n wrote:
 would using ghc-as-a-library to type (strings with) haskell  
 expressions at runtime help?
 
 On Mar 12, 2009, at 12:37 PM, Martin Hofmann wrote:
 
  I am doing meta-programming at runtime. So my program gets a full
  Haskell declaration in expression quotation ([d|...|]) modifies it and
  returns the modified expression. Therefore, I need type information of
  this expression, and any subexpression, at _runtime_ !  For example:
 
  [d| reverse x1 = y1 |]
 
   - rewrites_to -
 
  [d| reverse x2:xs = y2:ys |]
 
   - rewrites_to -
 
  [d| reverse x:xs = reverse xs ++  [x] |]
 
  reverse :: [a] - [a] implies
  x2,y2 :: a
  x1,y1,xs,ys :: [a]
 
  TH.reify is not applicable, because I need the information at runtime
  and I am in IO. I suppose Data.Dynamic does not work either, because  
  [|
  xs|] :: ExpQ and not [a].
 
  So it looks like I need my own type checker and inference and tag each
  subexpression with its type. If so, I can even omit TH and use my own
  data type for the abstract syntax tree. This annoys me a bit, because
  for me it seems that all I need is already there.
 
  Did anybody have similar problems, because I shouldn't be the only one
  doing dynamic typing in a static language? Is there a Haskell
  implementation of the paper Typing Dynamic Typing by Baars and
  Swierstra (http://people.cs.uu.nl/arthurb/dynamic.html ), so I can try
  out if this helps me?
 
  Any help, comments, and how-to-suggestions are highly welcome.
 
  Thanks a lot,
 
  Martin
 
 
 
  ___
  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