comp.lang.ada
 help / color / mirror / Atom feed
From: Paul Rubin <no.email@nospam.invalid>
Subject: Re: Haskell, anyone?
Date: Sun, 15 Nov 2015 20:11:17 -0800
Date: 2015-11-15T20:11:17-08:00	[thread overview]
Message-ID: <87d1vaoa6y.fsf@nightsong.com> (raw)
In-Reply-To: 87mvue50ey.fsf@ixod.org

Mark Carroll <mtbc@bcs.org> writes:
>> Say define a new integer subtype that can only take values from only
>> 1...20.  And have the compiler and run time check for this?

> I /can't/ think off-hand how to do this easily with Haskell (at least
> without unusual extensions) but I /think/ that Idris, ...

Haskell doesn't have subtypes per se.  You could define a new numeric
type that does a runtime check that a value created in that type is in
range, or throws an error otherwise.  This is called a "smart
constructor" in Haskell.  I think Ada's range types are similar: if X,
Y, and Z are in that 1..20 range type and X=15 and Y=15, then Z:=X+Y is
a legal Ada statement that doesn't raise any error until runtime.
Haskell's concept of types is entirely static (compile time) so Haskell
wouldn't consider "range 1..20" to be a type unles it could verify at
compile that Z:=X+Y was in range, by analyzing the code that produced X
and Y.

There's a new experimental Haskell feature called "refinement types"
which does things like that, and Idris (and Agda and Coq) are built to
do such things, but that's all way beyond what traditional Ada tries to
do.  It's more like SPARK on steroids where there a bunch of proof
obligations ("verification conditions" in SPARK terminology) that have
to be satisfied with almost every statement.

So I'd say don't worry about this til you've gotten more used to the
basics of Haskell.  If you really want to know more, there's another
online book "Software Foundations" that goes into it using Coq:

  http://www.cis.upenn.edu/~bcpierce/sf/current/index.html

Meanwhile there's a Haskell newsgroup comp.lang.haskell which is usually
quiet, but some knowledgeable Haskellers hang out there, so you can get
questions answered there.  The Freenode #haskell IRC channel is also big
and friendly, plus there's the mailing lists, etc.  See www.haskell.org
for more info.

  reply	other threads:[~2015-11-16  4:11 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-15 20:42 Haskell, anyone? mockturtle
2015-11-15 20:51 ` Paul Rubin
2015-11-15 20:53 ` Nasser M. Abbasi
2015-11-15 21:50 ` Mark Carroll
2015-11-15 22:11 ` mockturtle
2015-11-15 22:48   ` Nasser M. Abbasi
2015-11-15 23:05     ` Mark Carroll
2015-11-16  4:11       ` Paul Rubin [this message]
2015-11-16  5:17         ` Nasser M. Abbasi
2015-11-16  5:48           ` Paul Rubin
2015-11-16  5:59             ` Nasser M. Abbasi
2015-11-16  6:47               ` Paul Rubin
2015-11-16  8:45           ` Simon Wright
2015-11-16 14:38             ` Brian Drummond
2015-11-15 23:19     ` Jeffrey R. Carter
2015-11-16  9:36       ` J-P. Rosen
2015-11-16 18:14         ` Jeffrey R. Carter
2015-11-16  3:59   ` Paul Rubin
2015-11-16  8:33   ` Dmitry A. Kazakov
2015-11-16  9:33     ` mockturtle
2015-11-16  9:45       ` Paul Rubin
2015-11-16 10:25 ` Hadrien Grasland
2015-11-16 11:19   ` Simon Wright
2015-11-16 11:25     ` Hadrien Grasland
2015-11-16 13:59   ` G.B.
2015-11-16 20:24   ` Jeffrey R. Carter
2015-11-16 23:23   ` Paul Rubin
2015-11-17  8:26     ` Dmitry A. Kazakov
2015-11-17  9:10       ` Mark Carroll
2015-11-17 20:09         ` Dmitry A. Kazakov
2015-11-17 10:49     ` Hadrien Grasland
2015-11-17 12:01       ` G.B.
2015-11-17 16:43         ` Hadrien Grasland
2015-11-17 18:04           ` Paul Rubin
2015-11-17 21:42             ` Hadrien Grasland
2015-11-18  4:36               ` Paul Rubin
2015-11-18  8:48                 ` Hadrien Grasland
2015-11-18  9:23                   ` Paul Rubin
2015-11-18 10:44                     ` Hadrien Grasland
2015-11-18 11:02                       ` Dmitry A. Kazakov
2015-11-18 12:41                         ` G.B.
2015-11-18 23:06                       ` Randy Brukardt
2015-11-19  8:56                         ` Hadrien Grasland
2015-11-19  9:19                           ` Hadrien Grasland
2015-11-19 21:27                           ` Randy Brukardt
2015-11-24 12:03                           ` Jacob Sparre Andersen
2015-11-19  7:22                       ` Paul Rubin
2015-11-19  9:39                         ` Hadrien Grasland
2015-11-17 13:01       ` Thomas Løcke
2015-11-17 16:45         ` Hadrien Grasland
2015-11-18  0:11       ` Paul Rubin
2015-11-18  9:44         ` Hadrien Grasland
2015-12-06 12:59   ` David Thompson
2015-12-07  7:25     ` Hadrien Grasland
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox