Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Haskell programs be represented as Lisp S-expressions?

This would be useful for genetic programming, which usually use a Lisp subset as representation for programs.

I've found something called Liskell (Lisp syntax, Haskell inside) on the web, but the links are broken and I can't find the paper on it...

like image 802
Yan King Yin Avatar asked Jun 02 '11 02:06

Yan King Yin


People also ask

Is Haskell Lisp based?

They're both functional programming languages and Lisp influenced Haskell, but Haskell is not a Lisp derivative.

What is an s-expression in Lisp?

An s-expression, also known as a sexpr or sexp, is a way to represent a nested list of data. It stands for "symbolic expression," and it is commonly encountered in the Lisp programming language and variants of Lisp such as Scheme, Racket, and Clojure.

Which type of expressions are used in Lisp?

The syntactic elements of the Lisp programming language are symbolic expressions, also known as s-expressions. Both programs and data are represented as s-expressions: an s-expression may be either an atom or a list. Lisp atoms are the basic syntactic units of the language and include both numbers and symbols.


2 Answers

Check out Lisk, which was designed to fix the author's gripes with Liskell.

In my spare time I’m working on a project called Lisk. Using the -pgmF option for GHC, you can provide GHC a program name that is called to preprocess the file before GHC compiles it. It also works in GHCi and imports. You use it like this:

{-# OPTIONS -F -pgmF lisk #-}
(module fibs
  (import system.environment)

  (:: main (io ()))
  (= main (>>= get-args (. print fib read head)))

  (:: test (-> :string (, :int :string)))
  (= test (, 1))

  (:: fib (-> :int :int))
  (= fib 0 0)
  (= fib 1 1)
  (= fib n (+ (fib (- n 1))
              (fib (- n 2)))))

The source is here.

Also, if you don't actually care about Haskell and just want some of its features, you might want to check out Qi (or its successor, Shen), which has s-expression syntax with many modern functional-programming features similar to Haskell.

like image 56
Jonathan Tran Avatar answered Oct 13 '22 01:10

Jonathan Tran


You might be interested in a project I have been working on, husk scheme.

Basically it will let you call into Scheme code (S-expressions) from Haskell, and vice-versa. So you can intermingle that code within your program, and then process the s-expressions as native Haskell data types when you want to do something on the Haskell side.

Anyway, it may be useful to you, or not - have a look and decide for yourself.

like image 36
Justin Ethier Avatar answered Oct 13 '22 01:10

Justin Ethier