3 ms·
It seems to me like lisp-like (let's call this "somelisp", defined transpiled using Racket) syntax can be easily transpiled to other languages. If in Haskell I
by kovek 9y ago
It seems to me like lisp-like (let's call this "somelisp", defined transpiled using Racket) syntax can be easily transpiled to other languages.
If in Haskell I have for example:
myFunc :: [a] -> Int
myFunc = length
main = do
print $ length "foo"
It seems like you could easy express this in "somelisp" with:
(myFunc :: [] a -> Int)
(myfunc = length)
(main = do
print (length "foo"))
And since you're using lisp-like syntax, you have the possibility to use macros now!
Now, I don't know if it would simply be simpler to encode these macros in your "somelisp" language defined using Racket, if you should make a Haskell extension, or if you should just not use it at all?
What about having macros defined in specific files, and use the target language, say Haskell in your code, but whenever you want to use a macro, use a syntax that Haskell does not accept: $(mymacro print $ length "foo") and have a preprocessor convert this macro to its corresponding haskell code?
I am currently learning Haskell, so I don't know if there are more complex examples where this will not work.
- minikomi 9y agoYou nerdsniped me. Just spitballing a more racket-like way to write it.. (define myfunc length #:type (-> [a] Int)) (define main #:type (IO ()) (do (print (length "foo"))))
- Nullabillity 9y agoThat's pretty much how Template Haskell works, except it doesn't go through the lisp roundtrip.
- runeks 9y agoI know Haskell, and seeing your example Lisp code makes me completely dumbfounded: the parentheses look 100% redundant to me. What's the point of parenthesizing all expressions like that? Do they work as a replacement for newlines, which are ignored? It looks a bit like C's semi-colons, except twice as bad.