Re: DCGs as algebraic types

Stassa Patsantzis <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
(Originaly sent by jrfisher; confused as to how it fell off the list but forwarding to preserve continuity; hope it ends up in the right thread...)


On Thursday, 31 October 2013, 1:25, John Fisher <[email protected]> wrote:
 
Naive, sure, but pretty good, just the same.

This is an excellent observation, but 
the relationship between formal grammar and
type specifications is sort of marginal ...
(I think.)

Think about how to make the analogy more specific.
There are "types of grammars", but are there "type grammars"?
I'll think about this some.

JRF
________________________________________

From: [email protected] [[email protected]] On Behalf Of Stassa Patsantzis [[email protected]]
Sent: Wednesday, October 30, 2013 4:06 PM
To: Swi-prolog mailing list
Subject: [SWIPL] DCGs as algebraic types

Hi list,

When I look at a grammar rule like the following:

list --> [].
list --> [H|T], { list(T,[]) }.

- I can't help but think that it looks a lot like an algebraic data type. Say
for instance, the following example from wikipedia:

data List a = Nil | Cons a (List a)

-which is almost identical to the above, except for the fact that 'a' is a typed
variable. We could however write something like this:

int(A) --> [A], { integer(A) }.

- or even define our own types, such as:

type --> [t] | [y] | [p] | [e].

So that the following:

list --> [].
list --> [H|T], { type([H], []), list(T, []) }.

- would only be true if the input H was one of t,y,p or e, or a list of such,
therefore conforming to what looks a lot like a type constraint, to me at least.

So does that all sound too naive? Or did I just reinvent someone's wheel? Is
there any good reason why not to use DCG's to do type checking like above?

- Stassa.
-------------- next part --------------
HTML attachment scrubbed and removed
_______________________________________________
SWI-Prolog mailing list
[email protected]
https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
-------------- next part --------------
HTML attachment scrubbed and removed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.