Re:ARMv7 vs. x86-64: Pathfinding benchmark of C++, D, Go, Ni...
by jarcane on Saturday December 20, 2014 @06:53AM
(#8776424)
The Racket and Lisp comments are a bit odd. To the best of my knowledge Typed Racket does support gradual typing, and as well, comparing it's compatibility to Scheme is a category error: Racket is not Scheme anymore, that's why it's called Racket now and not PLT Scheme.
[ Parent
| on HN ]
Re:ARMv7 vs. x86-64: Pathfinding benchmark of C++, D, Go, Ni...
by logicchains on Saturday December 20, 2014 @06:59AM
(#8776430)
>To the best of my knowledge Typed Racket does support gradual typing
If you take a Racket program and change the language to Typed Racket, you'll get flooded with compiler errors. Or at least that's been my experience.
>Racket is not Scheme anymore
I'll update the post to note this, thanks.
Re:ARMv7 vs. x86-64: Pathfinding benchmark of C++, D, Go, Ni...
by klibertp on Saturday December 20, 2014 @10:34AM
(#8776843)
> If you take a Racket program and change the language to Typed Racket, you'll get flooded with compiler errors. Or at least that's been my experience.
That's because when using `#lang typed/racket` you literally change the language you're writing and that includes the syntax of some very fundamental forms (like define or struct).
You can mix typed and untyped code freely as long as they are separated by module boundaries. Something like this:
#lang racket/base
(module with-types typed/racket
(provide a)
(: a (-> String Integer))
(define (a x) 0))
(module without-types racket
(require (submod ".." with-types))
(provide a))
But it's definitely not as convenient as Erlang's Dialyzer, TypeScript, Dylan or similar success/gradual/occurrence/soft-typing solutions for sure.
Re:ARMv7 vs. x86-64: Pathfinding benchmark of C++, D, Go, Ni...
by kuschku on Saturday December 20, 2014 @10:24AM
(#8776818)
You can use typed/racket with optional types, it’s kinda easy.
Re:ARMv7 vs. x86-64: Pathfinding benchmark of C++, D, Go, Ni...
by klibertp on Saturday December 20, 2014 @10:38AM
(#8776854)
How? The docs say (http://docs.racket-lang.org/ts-guide/more.html#(part._when-a...) that you have to provide type annotations in certain cases.
Re:ARMv7 vs. x86-64: Pathfinding benchmark of C++, D, Go, Ni...
by bad_login on Saturday December 20, 2014 @08:32AM
(#8776593)
I just made the code a little more idiomatic
- avoided using the box arount max
- used a named let for loop and made it terminal recursive
removed the box improve performance from 10s to a 9s.
#lang typed/racket
(struct: route ([dest : Integer] [cost : Integer]) #:transparent)
(struct: node ([neighbours : (Listof route)]) #:transparent)
(: str->int (String -> Integer))
(define (str->int str)
(define n (string->number str))
(if n (numerator (inexact->exact (real-part n))) 0))
(: read-places (-> (Vectorof node)))
(define (read-places)
(define lines
(file->lines "agraph"))
(define num-lines (str->int (car lines)))
(define nodes (build-vector num-lines (lambda (n) (node `()))))
(let loop ([i : Integer 0])
(define nums (string-split (list-ref (cdr lines) i)))
(define len (length nums))
(when (and (> len 2) (> (length lines) (+ i 2)))
(let ([node-id (str->int (list-ref nums 0))]
[neighbour (str->int (list-ref nums 1))]
[cost (str->int (list-ref nums 2))])
(define new-node (node
(append (node-neighbours (vector-ref nodes node-id))
(list (route neighbour cost)))))
(vector-set! nodes node-id new-node)
(loop (+ i 1)))))
nodes)
(: get-longest-path ((Vectorof node) Integer (Vectorof Boolean) -> Integer))
(define (get-longest-path nodes node-id visited)
(vector-set! visited node-id #t)
(define sum
(foldr
(lambda ([neighbour : route] [max : Integer])
(if (not (vector-ref visited (route-dest neighbour)))
(let ([dist (+ (route-cost neighbour) (get-longest-path nodes (route-dest neighbour) visited))])
(if (> dist max)
dist
max))
max))
0
(node-neighbours (vector-ref nodes node-id))))
(vector-set! visited node-id #f)
sum)
(define nodes (read-places))
(define visited : (Vectorof Boolean) (build-vector (vector-length nodes) (lambda (n) #f)))
(define start (current-inexact-milliseconds))
(define len (get-longest-path nodes 0 visited))
(define duration (- (current-inexact-milliseconds) start))
(printf "~a LANGUAGE Racket ~a\n" len (inexact->exact (floor duration)))
Re:ARMv7 vs. x86-64: Pathfinding benchmark of C++, D, Go, Ni...
by logicchains on Saturday December 20, 2014 @09:01AM
(#8776639)
Thanks! I updated the code.