MagicHaskeller +RTS -N
sudo /etc/init.d/lighttpd start
Susumu Katayama 片山 晋
October, 2015 2015年10月9日
This is another good option because we will not use GUI.
Please install the 2014 or 2015 version.
Unix: Add export PATH=$HOME/.cabal/bin/:$PATH
to .bashrc
or so.
Windows: Add %APPDATA%\cabal\bin
to Path
. (But this may be unnecessary when using the 2015 version of Haskell Platform.)
$ cabal update
$ cabal install -j MagicHaskeller
On Windows + Platform 2014 you may need to use
$ cabal install -j MagicHaskeller --flags="-NETWORKURI"
The point is to force to use the already-installed version of the network package.
You may need to unregister some package temporarily, and restart installation again.
In my case, I had to unregister the HTTP
package, so
$ ghc-pkg unregister HTTP
$ cabal install -j MagicHaskeller
expr | ::= | variable | sequence of alphanumeric letters (or _ or ') starting with a small letter
小文字から始まる英数字(と_と')の列。
e.g. a , x , map , filter |
| | constructor | sequence of alphanumeric letters (or _ or ') starting with a capital letter
大文字から始まる英数字(と_と')の列。 e.g. Nothing | |
| | literal | e.g. 0 , 'c' , "string" | |
| | expr expr | curried function application
関数適用. (引数が複数ならカリー化) | |
| | \ pattern ... pattern -> expr |
lambda abstraction
ラムダ抽象
| |
| | expr op expr | e.g. 3 + 4 / 5 There are different precedences 演算子ごとに優先順位あり | |
| | section | e.g. (*) (equivalent to \x y -> x*y ), (4-) (equivalent to \x -> 4-x ), (+3) (equivalent to \x -> x+3 ) (though (-2) is "minus two" as in mathematics)
(4-) (\x -> 4-x と同じ), (+3) (\x -> x+3 と同じ) (ただし (-2) は数学やC言語と同じ意味。)
| |
| | ( expr , ... , expr ) |
tuple. Note that the parentheses are mandatory.
() is the only value in the unit type.
tuple. カッコは必須
() は unit型() の唯一の要素.
| |
| | if expr then expr else expr | conditional条件式。見ての通り。 | |
| | [ expr , ... , expr ] |
enumerated list. The empty list is
[] enumerated list. The empty list is
[] | |
| | [ expr .. expr ] |
e.g. [1..5] == [1,2,3,4,5] and ['a'..'c'] == ['a','b','c'] == "abc" | |
| | expr :: ctxttype | type signature |
op | ::= | varop | string of symbols not starting with ::以外から始まる記号の列。e.g. * , ++ |
| | conop | string of symbols starting with ::から始まる記号の列。e.g. : , :+ |
pattern | ::= | variable | bind the variable to the value変数パターン |
| | _ | ignore the value (wild card) ワイルドカード。結果は捨てられる。 |
ctxttype | ::= | ctxt => type | type with context (constraint by type class) コンテキスト(型クラスによる制約)つき型 |
| | type | type without context コンテキストのない型 |
type | ::= | variable | type variable 型変数 |
| | constructor | type constructor 型コンストラクタ | |
| | type type | type application 適用 | |
| | type -> type | function type (left associative)関数の型。左結合。 | |
| | ( type , ... , type )
| tuple, e.g., (Int,Char) . The unit type is
() .unit型は () . | |
| | [ type ] | list, e.g., [Integer] |
Int
Integer
Char
[
T]
String
String = [Char]
and "abc" == ['a','b','c']
文字列.実は String = [Char]
で,"abc" == ['a','b','c']
(
T1, ..., Tn )
Float
, Double
IO
T T
is a member of type class C
C
are defined for type T
. T
が型クラスC
に属するT
に対して型クラスC
のメソッドが定義されている
class Eq a where -- Eq a <=> relation
(==) :: a -> a -> Bool -- (==) :: Eq a => a -> a -> Bool
-- is defined
data Nat = Zero | Succ Nat -- Take Nat as an example. (This is not in the library.)
class Eq a where -- Eq a <=> 型a上に関係
(==) :: a -> a -> Bool -- (==) :: Eq a => a -> a -> Bool
-- が定義される.
data Nat = Zero | Succ Nat -- 自然数を例にとる.ライブラリにはない.
instance Eq Nat where
Zero == Zero = True
Zero == Succ n = False
Succ m == Zero = False
Succ m == Succ n = m == n
(==), (/=) :: Eq a => a -> a -> Bool
(<), (<=), (>), (>=) :: Ord a => a -> a -> Bool
(+), (-), (*) :: Num a => a -> a -> a
(/) :: Fractional a => a -> a -> a
div
rather than (/)
)(/)
ではなくdiv
)Num a => a
,fromInteger :: Num a => Integer -> a
which is a method of Num
Fractional a => a
,fromRational :: Fractional a => Rational -> a
which is a method of Fractional
Num a => a
という型を持つ.Num
のメソッドであるfromInteger :: Num a => Integer -> a
を使って型変換Fractional a => a
という型を持つ.Fractional
のメソッドであるfromRational :: Fractional a => Rational -> a
を使って型変換Library
Executable MagicHaskeller
Executable MagicHaskeller.cgi
Just try these (not at the root of the source directory):
$ MagicHaskeller -?
$ MagicHaskeller -d 5 -i
$ MagicHaskeller --excel -d 7 -i
Ctrl-d
to exit.
And try this if your notebook has more than 64GB memory (same amount as our backend server in Japan):
$ MagicHaskeller -i -d 7 -2 +RTS -N8
+RTS
indicates that the following options are passed to the GHC runtime system.
Use +RTS -?
for available RTS options.
./predicates
.
$ MagicHaskeller -d 5 -t predicates -i
predicates
are automatically supplied in parallel at the background.$ MagicHaskeller -d 5 -n -t predicates -s predicatesServed -i
predicates
are automatically supplied in parallel, then, queries in predicatesServed
are supplied sequentially, then the interactive mode starts.~/.cabal/share/MagicHaskeller-0.9.6.4.5/MagicHaskeller/
(Un*x)%APPDATA%\cabal\MagicHaskeller-0.9.6.4.5\MagicHaskeller\
(Windows)-s
is useful for evaluating the speed rather than for real training.
$ nohup MagicHaskeller -d 7 -2 -n -t predicates -s predicatesServed -p 55443 +RTS -N8 -RTS &
$ nohup MagicHaskeller --excel -d 8 -p 55444 +RTS -N4 -RTS &
/usr/local/bin/MagicHaskeller
to the CGI directory./usr/local/share/MagicHaskeller-0.9.6.4.4/MagicHaskeller.conf
.Foo.cgi
uses Foo.conf
.
So, the installation command for the CGI server is:
$ cabal install MagicHaskeller --with-compiler=ghc-7.4.1 --global --root-cmd=sudo
(Adapt the GHC version number.)
mkdir foo
cd foo
cabal unpack MagicHaskeller
(Just execute cabal install
(without the package name) to build and install the source tree under the current directory.)
MagicHaskeller/SimpleServer.hs
main
for Executable MagicHaskeller
MagicHaskeller/LibTH.hs
MagicHaskeller/LibTH.hs
MagicHaskeller.lhs
MagicHaskeller -2
MagicHaskeller -w
MagicHaskeller -b
MagicHaskeller.lhs
\f x n -> iterate f x !! abs n
) are considered 1 function\f x n -> iterate f x !! abs n
)は1つの関数と数える。gcd
) with less priority are considered to involve 1 or 2 applicationsgcd
) は、優先順序を下げて、関数適用が1〜2回入っていると考えて数える。
You can execute synthesis without rebuilding executables, from GHCi (or GHC interactive).
$ ghci -fth -package MagicHaskeller
Prelude> :m +MagicHaskeller.LibTH
Prelude MagicHaskeller.LibTH> filterThen (\f -> f [1,2,3] == [3,3,3]) (everything pgfull False) >>= pprs . take 6
Prelude MagicHaskeller.LibTH> let mypg = mkPG $(p [| (map :: (a -> b) -> (->) [a] [b], show :: Integer -> [Char]) |]) :: ProgGenSF
Prelude MagicHaskeller.LibTH> filterThen (\f -> f [1,2,3] == ["1","2","3"]) (everything mypg False) >>= pprs . take 7
Prelude MagicHaskeller.LibTH> :m +MagicHaskeller.Minimal
Prelude MagicHaskeller.LibTH MagicHaskeller.Minimal> map pprint $ concat $ take 6 $ f1EF postprocess (\f -> f [1,2,3::Int] == "123") pgfull False
See the library documentation (mainly of module MagicHaskeller) for details.
Pitfalls:
[Char]
is replaced with String
, because MagicHaskeller does not know type synonyms.Integer
is replaced with Int
, because Haskell infers [1,2,3]::[Integer]
rather than [Int]
.Other tips for efficiency:
(->) A B
= A -> B
, and A -> B -> C
= (->) A (B -> C)
= A -> (->) B C
= (->) A ((->) B C)
.
However, the prefixed (->)
has a special meaning when creating the component library:
constructor applications never appear as the first argument of (->)
.
E.g. foldr :: (a -> b -> b) -> b -> [a] -> b
should be written as foldr :: (a -> b -> b) -> b -> (->) [a] b
because both foldr op x []
and foldr op x (y:ys)
are reducible and thus should not be generated.flip
and (.)
are used to change the argument order and narrow the search.
After postprocessing they become simplified.