cancel
Showing results for 
Search instead for 
Did you mean: 

A few questions

Former Member
0 Kudos

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>

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

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.


Former Member
0 Kudos

<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>