Re: [stack] Fwd: [Factor-talk] cleave, 2cleave, and spread

John Nowak <[email protected]>
Newsgroups gmane.comp.lang.concatenative
Message-ID <[email protected]>
On Apr 4, 2008, at 1:09 AM, Daniel Ehrenberg wrote:

> If cleave/2cleave/spread are considered to take an array as an
> argument, they can't be typed. But if they take a heterogeneous
> vector, whose length and the types of all entries are known before
> runtime, then it should be possible to give it an overall type given
> some mechanism to do calculations on types. I just don't know what
> that type is, exactly...

If you wanted to give a type to 'cleave', it would look like this:

    cleave :: A(0) b {[A(0) b -> A(1)] ... [A(N-1) b -> A(N)]} -> A(N)

The reason for the complicated type is that you need to express not  
only that the types of each element may be different, but also that  
they are dependent on each other and can be sensibly composed.

> though, I think a dup/swap/dip/drop base would be easier to work with
> in a statically typed language.

Absolutely; they're simple, direct, and efficient to implement. Of  
course, it's easy to imagine reducing this list. For example:

    drop  :: A b -> b
    blort :: A b c [A -> D] -> D c b b

And from this we can derive the standard functions as such:

    swap = [] blort drop
    dup  = swap [] blort
    nip  = swap drop
    dip  = [] swap blort drop nip
    i    = [] dip drop
    ...

There is possibly a cleaner typed two function base than this; it's  
just my first stab at it. I am not sure though there is a cleaner base  
where only one of the two functions is a combinator.

- John
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.