[Haskell-cafe] Newbie question about tuples

peterv bf3 at telenet.be
Fri Jul 13 10:55:06 EDT 2007


> with guaranteed termination, of course

Just out of curiosity (not Haskell related): I always get confused when
people speak about "guaranteed termination"; what about the halting problem?
In which context can one check for "guaranteed termination", as the halting
problem says it's not *generally* possible? 

-----Original Message-----
From: haskell-cafe-bounces at haskell.org
[mailto:haskell-cafe-bounces at haskell.org] On Behalf Of Jonathan Cast
Sent: Friday, July 13, 2007 16:21
To: haskell-cafe at haskell.org
Subject: Re: [Haskell-cafe] Newbie question about tuples

On Friday 13 July 2007, peterv wrote:
> I'm beginning to see that my old implementation in C++ clutters my Haskell
> design.
>
> You see, in C++ I can write:
>
> // A vector is an array of fixed-length N and elements of type T
> template<typename T, int N> struct Vector
> {
>   T Element[N];
>
>   friend T dot(const Vector& a, const Vector& b)
>   {
>      T result = 0;
>      for( int i=0; i<N; ++i )
>      {
>         result += a.Element[i] * b.Element[i];
>      }
>      return result;
>   }
> };
>
> So basically a wrapper around a fixed-size array of any length.
> Implementations of (+), (-), dot, length, normalize, etc... then work on
> vectors of any size, without the overhead of storing the size, and with
> compile-time checking that only vectors of the same size can be used,
> etc... This also fits in nicely when creating a Matrix<T,N,M> class.
>
> I don't think Haskell has something like a "fixed-length array" or
constant
> expressions that *must* be resolved at compile-time (like the N in the C++
> template)?

I'm surprised no one has posted anything on type-level programming yet.  You

might google for that.  And GHC 6.8 will have true type-level functions
(with 
guaranteed termination, of course) which will help.  But I'm sure a good 
google will turn up a clearer explanation than I can provide; I've never 
needed or wanted to understand the type-level stuff.

Jonathan Cast
http://sourceforge.net/projects/fid-core
http://sourceforge.net/projects/fid-emacs
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe at haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

No virus found in this incoming message.
Checked by AVG Free Edition. 
Version: 7.5.476 / Virus Database: 269.10.4/898 - Release Date: 12/07/2007
16:08
 

No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.476 / Virus Database: 269.10.4/898 - Release Date: 12/07/2007
16:08
 



More information about the Haskell-Cafe mailing list