Created
January 18, 2012 10:23
-
-
Save bergmark/1632326 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Haskell: | |
| data Select = FirstAlternative String String | |
| | SecondAlternative Select Select | |
| | ThirdAlternative Select | |
| printSelect :: Select -> IO () | |
| printSelect (FirstAlternative str1 str2) = | |
| putStr("FirstAlternative(" ++ str1 ++ ", " ++ str2 ++ ")") | |
| printSelect (SecondAlternative sel1 sel2) = do | |
| putStr("SecondAlternative(") | |
| printSelect(sel1) | |
| putStr(",") | |
| printSelect(sel2) | |
| putStr(")") | |
| printSelect (ThirdAlternative sel) = do | |
| putStr("ThirdAlternative(") | |
| printSelect(sel) | |
| putStr(")") | |
| ----- | |
| MetaModelica: | |
| uniontype Select | |
| record FirstAlternative | |
| String x1; | |
| String x2; | |
| end FirstAlternative; | |
| record SecondAlternative | |
| Select x1; | |
| Select x2; | |
| end SecondAlternative; | |
| record ThirdAlternative | |
| Select next; | |
| end ThirdAlternative; | |
| end Select; | |
| function printSelect | |
| input Types.Select inValue; | |
| algorithm | |
| _ := match inValue | |
| case Types.FirstAlternative(str1,str2) | |
| local | |
| String str1; | |
| String str2; | |
| equation | |
| print("FirstAlternative(" + str1 + "," + str2 + ")"); | |
| then (); | |
| case Types.SecondAlternative(sel1,sel2) | |
| local | |
| Types.Select sel1; | |
| Types.Select sel2; | |
| equation | |
| print("SecondAlternative("); | |
| printSelect(sel1); | |
| print(","); | |
| printSelect(sel2); | |
| print(")"); | |
| then (); | |
| case Types.ThirdAlternative(sel) | |
| local | |
| Types.Select sel; | |
| equation | |
| print("ThirdAlternative("); | |
| printSelect(sel); | |
| print(")"); | |
| then (); | |
| end match; | |
| end printSelect; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment