count = 0; let substr_len = substr.len(); let upper_bound = value.len() - substr_len + 1; for c in 0..upper_bound { let possible_match = &value[c..c+substr_len]; if possible_match == substr { count += 1; } } count } Zbigniew Siciarz @zsiciarz siciarz.net
ccall "count_substrings" count_substrings :: CString -> CString -> IO Int main :: IO () main = do value <- newCString "banana" substr <- newCString "na" count_substrings value substr >>= print Zbigniew Siciarz @zsiciarz siciarz.net