POV-Ray : Newsgroups : povray.off-topic : Why is Haskell interesting? : Re: Why is Haskell interesting? Server Time
4 Sep 2024 09:18:09 EDT (-0400)
  Re: Why is Haskell interesting?  
From: Warp
Date: 26 Feb 2010 12:28:12
Message: <4b8804ac@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> Invisible wrote:
> > Haskell has automatic type inference, for example.

> Lots of languages have this a little. In C# you can say
>    var x = new Vector2(0,3);
> and x gets the type Vector2.  Automatic casting in languages is a similar 
> thing, methinks.

  The next C++ standard will instroduce something similar: The 'auto' type.
The idea is that since the compiler can deduce the type of the variable in
most situations, then why should the programmer have to specify it explicitly?

  Thus you will be able to write things like:

    for(auto iter = v.begin(); iter != v.end(); ++iter) ...

  The compiler can see what is the return type of v.begin(), so there's no
need for the programmer to know it. Hence he can just specify 'auto' as the
variable type.

  This will be more than just a convencience shortcut, though. For example,
it allows doing something like this:

    template<typename Container>
    void foo(const Container& container)
    {
        auto element = container[0];
        ....
    }

  The type of the element may differ from container to container, and if
you need a variable of that type, previously there was no fool-proof way
of doing that. (The usual way around this to define a typedef inside the
container named "value_type" which defines the type of the elements, but
the 'auto' keyword will eliminate the need for that.)

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.