Tuesday, 15 June 2010

Typed Racket: Creating generic types with define-type -


I'm trying to get a bit in the typing racket, but I'm having some difficulty (validly build No) Experiment to experiment.

It is that I was originally:

  #lang typed / racket (: Generate-list (all (a) ((A -> A) (integer - & Gt; a) integer -> (define (list-function list-function number-item) (two: loop: (list A) ((count: integer 0) (result: (List) (list)) (if (> = count num-items) (reverse result) (loop (+ count1) (opposition (function (count of location-function)))))) ); --------------------------------- (f - number -> number)) (defined) Fx (* Xx)) (: locf (integer -> gt; Khya)) (defined (locf x) x); --------------------------------- (displayln (Generate- List F locf 10))   

Output is:

  (0 1 4 9 16 25 36 49 64 81)   

Which is good then I thought that I can make a document by giving it a better function and location work by a defined type:

  #lang typed / racket (define- Type (ListGenFunction A) (A ->) (defined-type (ListGenLocFunction A) (integer - & gt; A)) :: list of inventory (all (A) (ListGenFunction ListGenLocFunction Integer -> (List of A)) (Define (Generate List Function Location-Function Number-item) (Two: Loop: (A) (List: integer 0) (results: (list A) (list))) (if (> = count num-items) (reverse result) (loop (+ count1) (opposition (function ( Location-work count)) results))))); ----------- Number! ------------ (: f ListGenFunction) (defined (f x) (* x x)) (: locf ListGenLocFunction) (defined (locf x) x); --------------------------------- (displayln (generator list F locf 10))   Now these problems have started (and I really hope some experienced typing racqueters are not facing difficulties right now). For one, type checker gives me an error on the line where I define the message is rather long, but it is basically: "type tester: function not matching function in domain: type: ... in: (* Xx) ". I thought that I have defined a type in which there is a parameter of normal type A that gives normal type A? (* X x) will not work? Or need "tag" type? (For example, like the list of languages ​​like C ++ & lt; int & gt;)  

at that top: a return type in my type-definition for the generic-list function (" Listof A) ". But that has not been declared at all that the same parameter as A, with the listGenFunction and ListGenLocFunction expectations. I want to make that relation, however, so that any person using that function can be sure that the types of jobs returned to them match the types of return items.

How can I do this correctly?

PS: I'm not sure if anyone told me my intention in the last paragraph, then nobody can understand it. But if you take some general pseudo-C ++ code, then I have to get the following:

  list & lt; T & gt; Generate-List (LGF & Lt; TACDF, LGFF & Lt; T & End; Lock, Ant Count) {...}   

so that all t is exactly the same.

There are two problems, both of which stem from the same illusion.

For example, you are using a common type, ListGenFunction , without typing the typing racket (or the reader of your program) without informing it.

For example, code> F is not an arbitrary ListGenFunction , this is a ListGenFunction Works especially on numbers. Then you should write:

  (: ListGenFunction Integer)   

and

  (: locf (ListGenLocFunction ) Similarly, you should give a type of  generator list  in such a way:  
  (: list of inventory (all (ListGenFeature A) (ListGenLocFunction A) Integer - & gt; (A list of A)))   

It is quite similar that you are explicitly saying that you (A list) , Not just a list .

No comments:

Post a Comment