Are there types in this language?

46 views
Skip to first unread message

Matt Habel

unread,
Jan 26, 2012, 10:49:23 PM1/26/12
to last...@googlegroups.com
I was wondering if there was a way to denote type safe functions?

Ian Clarke

unread,
Jan 27, 2012, 9:02:18 AM1/27/12
to last...@googlegroups.com
Hmm, I had to think about this.  The way LastCalc processes user input to arrive at an output is rather unusual.

I think the closest analogy is to say that LastCalc is dynamically typed, like Python or Ruby, but really it's hard to say because LastCalc works quite differently to most programming languages internally.

Can you elaborate on what you would like to do?

Ian.

On Thu, Jan 26, 2012 at 9:49 PM, Matt Habel <habe...@gmail.com> wrote:
I was wondering if there was a way to denote type safe functions?

--
You received this message because you are subscribed to the LastCalc Group
http://groups.google.com/group/lastcalc?hl=en?hl=en



--
Ian Clarke

Matt Habel

unread,
Jan 27, 2012, 2:38:56 PM1/27/12
to last...@googlegroups.com
Well I was thinking about how to sum lists. I got down a function to sum a basic 1d list i.e sum[1,2, 3] = 6
However, I couldn't figure out how to sum 2d, or 3d, etc lists i.e sum[[1, 2], [3, 4]] = [3, 7] = 10

Here's how I defined sum for 1d lists
sum[] = 0
sum [Head ... Tail] = Head + sum Tail

So I was thinking, I'll check if it is an integer or a list then act accordingly. i.e
sum[1, [2, 3]]
Head = 1 (int)  + sum [2, 3]
This equates to 1 + [[2, 3]] and returns 1 + [2, 3]

However, if I could check if tail is a list, I could sum car Tail, where car[Head ... Tail] = Head

Or am I just going about this like a functional programming amateur?

Ian Clarke

unread,
Jan 27, 2012, 4:23:31 PM1/27/12
to last...@googlegroups.com
If I understand you correctly, I think this is what you want:

sum [] = 0
sum [H ... T] = H + sum T
sum [H ... T] = sum H + sum T

Then this works:

sum [[1,2], [3,4]] = 10

The pattern matching behaves appropriately depending on whether H is an integer (in which case H + sum T works), or whether H is itself a list (in which case sum H + sum T works).

Hope that makes sense,

Ian.

--
You received this message because you are subscribed to the LastCalc Group
http://groups.google.com/group/lastcalc?hl=en?hl=en

Thomas Woolford

unread,
Feb 6, 2012, 9:24:35 PM2/6/12
to last...@googlegroups.com
I'm sure you've heard comparisons to Haskell from everyone before, but is there a concept of "type" within the code?

i.e.

> t: [[1,2],[2,3]]
[[int]]
> t: ["abc", "xyz"]
[[char]] or [string] ?

Is this valid or nonsensical in lastcalc?

Ian Clarke

unread,
Feb 6, 2012, 9:32:15 PM2/6/12
to last...@googlegroups.com
LastCalc is basically dynamically typed, but the concept of a type is somewhat generalized, it's actually a bit like Prolog, where the idea is "this function can take those values If the function works when it takes them".  The reason is that LastCalc can backtrack, so if you typed:

1 pound in kg

It interprets "1 pound" as a weight, but if you type:

1 pound in euros

It interprets it as a currency.  So basically it is a "context-sensitive grammar", which it achieves through a backtracking parser.

It does have typing in one way that is as-yet undocumented, which is that if you define a function:

do something to SomeList = ...

The fact that the parameter ends with the word "List" means that it will only bind to something of type List. 

Currently this also works with "Map", "Num" or "Number", "Bool" or Boolean, "Amount" (a combination of a Number and a Unit like "miles"), "Fun" or "Function" which will only bind to a function (ie. a closure).

Ian.

--
You received this message because you are subscribed to the LastCalc Group
http://groups.google.com/group/lastcalc?hl=en?hl=en

Thomas Woolford

unread,
Feb 21, 2012, 7:58:34 PM2/21/12
to last...@googlegroups.com
That is actually a really intuitive way to handle type inference. Good Work man.

Ian Clarke

unread,
Feb 21, 2012, 9:22:36 PM2/21/12
to last...@googlegroups.com
On Tue, Feb 21, 2012 at 6:58 PM, Thomas Woolford <rocker....@gmail.com> wrote:
That is actually a really intuitive way to handle type inference. Good Work man.

Thanks :-)

Ian.
 
Reply all
Reply to author
Forward
0 new messages