diff --git a/collects/tests/typed-scheme/succeed/somesystempath.rkt b/collects/tests/typed-scheme/succeed/somesystempath.rkt new file mode 100644 index 0000000000..1ad85b21ac --- /dev/null +++ b/collects/tests/typed-scheme/succeed/somesystempath.rkt @@ -0,0 +1,27 @@ +#lang typed/racket + +(: unix-path SomeSystemPath) +(define unix-path (string->some-system-path "file.rkt" 'unix)) + +(: windows-path SomeSystemPath) +(define windows-path (string->some-system-path "file.rkt" 'windows)) + +(for: ((p : SomeSystemPath (list unix-path windows-path))) + (let ((long-path (build-path p 'up 'same p))) + (unless (path-for-some-system? p) + (error "Predicate failed")) + (explode-path long-path) + + (filename-extension p) + (path-only long-path) + (some-system-path->string long-path) + + )) + + +(when (equal? 'unix (system-path-convention-type)) + (find-relative-path (simplify-path (path->complete-path "foo")) (simplify-path (path->complete-path "foo/foo/foo")))) + + + + diff --git a/collects/typed-scheme/base-env/base-env.rkt b/collects/typed-scheme/base-env/base-env.rkt index 2d5d294161..96ef4b2495 100644 --- a/collects/typed-scheme/base-env/base-env.rkt +++ b/collects/typed-scheme/base-env/base-env.rkt @@ -394,7 +394,7 @@ [string->path (-> -String -Path)] -[build-path ((list -Pathlike*) -Pathlike* . ->* . -Path)] +[build-path ((list -SomeSystemPathlike*) -SomeSystemPathlike* . ->* . -Path)] [with-input-from-file (-poly (a) (->key -Pathlike (-> a) #:mode (one-of/c 'binary 'text) #f a))] [with-output-to-file @@ -750,6 +750,7 @@ [object-name (Univ . -> . Univ)] [path? (make-pred-ty -Path)] +[path-for-some-system? (make-pred-ty -SomeSystemPath)] ;; scheme/function [const (-poly (a) (-> a (->* '() Univ a)))] @@ -843,16 +844,23 @@ ;; scheme/path -[explode-path (-Pathlike . -> . (-lst (Un -Path (-val 'up) (-val 'same))))] -[find-relative-path (-Pathlike -Pathlike . -> . -Path)] +[explode-path (-SomeSystemPathlike . -> . (-lst (Un -SomeSystemPath (-val 'up) (-val 'same))))] +[find-relative-path (-SomeSystemPathlike -SomeSystemPathlike . -> . -SomeSystemPath)] [simple-form-path (-Pathlike . -> . -Path)] [normalize-path (cl->* (-Pathlike [-Pathlike] . ->opt . -Path))] -[filename-extension (-Pathlike . -> . (-opt -Bytes))] +[filename-extension (-SomeSystemPathlike . -> . (-opt -Bytes))] [file-name-from-path (-Pathlike . -> . (-opt -Path))] -[path-only (-Pathlike . -> . (-opt -Path))] -[some-system-path->string (-Path . -> . -String)] +[path-only (-SomeSystemPathlike . -> . (-opt -Path))] +[some-system-path->string (-SomeSystemPath . -> . -String)] [string->some-system-path - (-String (Un (-val 'unix) (-val 'windows)) . -> . -Path)] + (-String (Un (-val 'unix) (-val 'windows)) . -> . -SomeSystemPath)] + +[simplify-path (-SomeSystemPathlike [B] . ->opt . -SomeSystemPath)] +[path->complete-path + (cl->* (-> -Pathlike -Path) + (-> -SomeSystemPathlike -SomeSystemPathlike -SomeSystemPath))] +[system-path-convention-type (-> (Un (-val 'unix) (-val 'windows)))] + ;; scheme/file [fold-files diff --git a/collects/typed-scheme/base-env/base-types.rkt b/collects/typed-scheme/base-env/base-types.rkt index 1f63fe699b..9f7a88b959 100644 --- a/collects/typed-scheme/base-env/base-types.rkt +++ b/collects/typed-scheme/base-env/base-types.rkt @@ -77,6 +77,7 @@ [Any Univ] [Port -Port] [Path -Path] +[SomeSystemPath -SomeSystemPath] [Path-String -Pathlike] [Regexp -Regexp] [PRegexp -PRegexp] diff --git a/collects/typed-scheme/types/abbrev.rkt b/collects/typed-scheme/types/abbrev.rkt index 460818bef4..b9778e438d 100644 --- a/collects/typed-scheme/types/abbrev.rkt +++ b/collects/typed-scheme/types/abbrev.rkt @@ -143,6 +143,10 @@ (define -Prompt-Tag (make-Base 'Prompt-Tag #'continuation-prompt-tag? continuation-prompt-tag? #'-Prompt-Tag)) (define -Cont-Mark-Set (make-Base 'Continuation-Mark-Set #'continuation-mark-set? continuation-mark-set? #'-Cont-Mark-Set)) (define -Path (make-Base 'Path #'path? path? #'-Path)) +(define -OtherSystemPath (make-Base 'OtherSystemPath + #'(and/c path-for-some-system? (not/c path?)) + (conjoin path-for-some-system? (negate path?)) + #'-OtherSystemPath)) (define -Namespace (make-Base 'Namespace #'namespace? namespace? #'-Namespace)) (define -Output-Port (make-Base 'Output-Port #'output-port? output-port? #'-Output-Port)) (define -Input-Port (make-Base 'Input-Port #'input-port? input-port? #'-Input-Port)) @@ -159,8 +163,11 @@ (define -Port (*Un -Output-Port -Input-Port)) +(define -SomeSystemPath (*Un -Path -OtherSystemPath)) (define -Pathlike (*Un -String -Path)) -(define -Pathlike* (*Un -String -Path (-val 'up) (-val 'same))) +(define -SomeSystemPathlike (*Un -String -SomeSystemPath)) +;(define -Pathlike* (*Un -String -Path (-val 'up) (-val 'same))) +(define -SomeSystemPathlike* (*Un -String -SomeSystemPath(-val 'up) (-val 'same))) (define -Pattern (*Un -Bytes -Regexp -PRegexp -Byte-Regexp -Byte-PRegexp -String)) (define -top (make-Top))