Category:CafeOBJ
From Rosetta Code
CafeOBJ
This programming language may be used to instruct a computer to perform a task.
Listed below are all of the tasks on Rosetta Code which have been solved using CafeOBJ.
This programming language may be used to instruct a computer to perform a task.
See Also: 


Your Help Needed
If you know CafeOBJ, please write code for some of the tasks not implemented in CafeOBJ.
If you know CafeOBJ, please write code for some of the tasks not implemented in CafeOBJ.
Basic Information[edit]
CafeOBJ is a algebraic specification language. It has an executable sublanguage which is broadly similar to Haskell or ML. CafeOBJ has many advanced features including: multiple logics, flexible mixfix syntax, powerful and clear typing system with ordered sorts, parametric modules and views for instantiating the parameters, and module expressions, and more. Many of these features are inherited from OBJ3
Download , Tutorial , Lectures , Video1 , Video2 ,
Examples[edit]
 Text file called say Hello.cafe ,contains the following
mod! HELLOWORLD {
pr(STRING)
op hello : > String
eq hello = "Hello World" .
}
 Bring *in* the file at CafeOBJ prompt
in hello.cafe
 Open the HELLOWORLD module
open HELLOWORLD
 Execute with the reduce command
reduce hello .
 Gives ("Hello World"):String
 Here is a sorting program.
mod! SORTINGNAT {
pr(NAT)
[Nat < Strg ]
 Simple list structure
op nil : > Strg
op _._ : Strg Strg > Strg { assoc id: nil }
vars N N' : Nat
 A very short sorting program using on transition equation in POA logic, which is a type of rewrite logic/
 The program is in the form of a condition transition, which will swap N and N' if N is larger or equal to N'.
 This is a equation in POA logic so there is no need for an intermediate variable to do the swap.
ctrans [swap] : (N . N') => (N' . N) if N' <= N .
}
**> Sorting natural numbers using exec command
open SORTINGNAT
exec (3 . 2 . 1) .
**> We can consider sorting as a path through the state space of the permutations of N numbers.
**> There are N! permutations only one of which is sorted.
**> Sorting natural numbers using search command
**> we can use (show path N) with this command, where N is the number of possible states.
red (3 . 2 . 1) =(1,1)=>* (1 . 2 . 3) .
red (3 . 2 . 1) =(1,2)=>* (1 . 2 . 3) .
red (3 . 2 . 1) =(1,3)=>* (1 . 2 . 3) .
**> search for any number of solutions at any depth
red (3 . 2 . 1) =(*,*)=>* (1 . 2 . 3) .
**> print the transitions from initial to goal state
show path 5
eof
Pages in category "CafeOBJ"
This category contains only the following page.