{-# LANGUAGE ScopedTypeVariables #-} {- Copyright 2011 Ken Takusagawa This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -} module Factor_cmd where{ import System.Process; factor :: Integer -> IO([](Integer)); factor x = ((readProcess "factor" [(show x)] "") >>= (return . tail . (map read) . words)); is_prime :: Integer -> IO(Bool); is_prime x = (case (compare x 1) of { GT-> ((factor x) >>= (return . length) >>= (return . (\lambda_case_var ->case lambda_case_var of { 1-> True; _ -> False }))); _ -> (return False) }); next_prime :: Integer -> IO(Integer); next_prime try = ((is_prime try) >>= (\lambda_case_var ->case lambda_case_var of { True-> (return try); _ -> (next_prime ((+) 1 try)) })) }