Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
function types
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
max.wolf  
View profile  
 More options Dec 27 2011, 5:29 pm
From: "max.wolf" <23.14...@gmail.com>
Date: Tue, 27 Dec 2011 14:29:25 -0800 (PST)
Local: Tues, Dec 27 2011 5:29 pm
Subject: function types
It was a pleasent surprise to see "interfaces" introduced in pure
0.50.
I think it is a nice step forward.
Now i wonder if it would be a good idea to have type declarations for
functions as well.
Something like:

public factorial::number;

with the semantics that an exception is thrown by the runtime in case
the computed value doesn't match the type declaration.
Perhaps this could even render the "defined" pragma unnecessary.

Max


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
max.wolf  
View profile  
 More options Dec 27 2011, 5:47 pm
From: "max.wolf" <23.14...@gmail.com>
Date: Tue, 27 Dec 2011 14:47:20 -0800 (PST)
Local: Tues, Dec 27 2011 5:47 pm
Subject: function types
It was a pleasent surprise to see "interfaces" introduced in pure
0.50.
I think it is a nice step forward.
Now i wonder if it would be a good idea to have type declarations for
functions as well.
Something like:

public factorial::number;

with the semantics that an exception is thrown by the runtime in case
the computed value doesn't match the type declaration.
Perhaps this could even render the "defined" pragma unnecessary.

Max


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Albert Graef  
View profile  
 More options Jan 5, 10:20 am
From: Albert Graef <Dr.Gr...@t-online.de>
Date: Thu, 05 Jan 2012 16:20:59 +0100
Local: Thurs, Jan 5 2012 10:20 am
Subject: Re: [pure-lang] function types
Hi Max, a happy new year to you and everybody!

Sorry for the late reply, I was somewhat busy over the holidays.

On 12/27/2011 11:29 PM, max.wolf wrote:

> It was a pleasent surprise to see "interfaces" introduced in pure
> 0.50.
> I think it is a nice step forward.
> Now i wonder if it would be a good idea to have type declarations for
> functions as well.

I left this out on purpose. For the purpose of defining a type via a
description of its interface, the result type of a function isn't really
needed anywhere.

> Something like:

> public factorial::number;

> with the semantics that an exception is thrown by the runtime in case
> the computed value doesn't match the type declaration.

A simple approach like this won't fly in Pure since many functions are
polymorphic. So we'd need to add a lot of syntactic baggage to the
language to just declare something like "this function returns type x if
applied to such and such arguments".

But there's already an easy way to get that with ordinary Pure code.
Just define yourself an 'assert' function, e.g., like this:

assert p x = if p x then x else throw (bad_assert p x);

Then you can write, e.g.,

factorial n = assert numberp (if n>0 then n*factorial (n-1) else 1);

An alternative would be to define 'assert' as a macro that could
conditionally be optimized away at compile time if not wanted, similar
to how C's 'assert' works:

//#! --disable assertions
#! --if assertions
def assert p x = if p y then y else throw (bad_assert p y) when y = x end;
#! --else
def assert p x = x;
#! --endif

Cheers,
Albert

--
Dr. Albert Gr"af
Dept. of Music-Informatics, University of Mainz, Germany
Email:  Dr.Gr...@t-online.de, a...@muwiinfa.geschichte.uni-mainz.de
WWW:    http://www.musikinformatik.uni-mainz.de/ag


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »