Skip to Content
author's profile photo Former Member
Former Member

A few questions

I&#39;ve just started playing with CAL, and have a few questions. As I&#39;m familiar with Haskell, they mostly take the form of "this is harder in CAL than Haskell, am I doing it the right way" <div><br /></div><div>1. Am I correct in thinking that there is no way of defining a Synonym for a type, e.g. in Haskell I&#39;d say: </div><div>type Picture = [[Char]] </div><div><br /></div><div>2. String is not equivalent to [Char]? </div><div><br /></div><div>3. You can only pattern match with a case statement? </div><div><br /></div><div>Thanks,</div><div> Tom</div>

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Oct 25, 2006 at 04:12 AM

    Hi Tom,


    Coming from a Haskell background, you'll find that CAL is a simpler language than Haskell. We have a design principle that we should not overload the lanugage too much with syntactic sugar that does essentially the same job, or that can reasonably easily be achieved through regular function application.


    Â

    Anyway, to your specific questions:

    1. Correct. We may add 'newtype' at some point, but we do not support type synonyms.

    2. String is different to . CAL is fundamentally designed for tight integration with Java, and CAL&#39;s String is actualy a java.lang.String. Similarly CAL&#39;s Char is a Java Char. There are functions to easily convert between these (toList, fromList), and indeed to convert to/from Array Char also.

    3. Yes, patterns are matched in case expressions alone. CAL does not support the multiple equation style, with pattern matching on the formal arguments of function definitions.Â



    There is doc called "CAL for Haskell Programmers" in the 'docs' directory of the unzipped installation that you might find interesting if you haven't already discovered it. This is high-level, but explains some of the philosophies and material differences between Haskell and CAL.


    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      <p>I was translating the Picture example from The Craft of FP -- it uses: </p><p>type Picture = [[Char]] </p><p>&nbsp;</p><p>which allows a lot of succinct zero-point style functions, e.g: </p><p>sideBySide :: Picture -> Picture -> Picture </p><p>sideBySide = zipWith (++) </p><p>Of course you could translate this to CAL very easily if you just substituted [[Char]] for Picture, but I wanted to use a type for Picture. The CAL version was looking very clumsy until I realised I needed to lift functions into the Picture type, that allows a pretty neat solution. </p><p>Tom</p>

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.