src/Tools/Haskell/Haskell.thy
changeset 74204 c832f35ea571
parent 74203 92f08f3d77bd
child 74205 5f0f0553762f
equal deleted inserted replaced
74203:92f08f3d77bd 74204:c832f35ea571
   220 {-# LANGUAGE InstanceSigs #-}
   220 {-# LANGUAGE InstanceSigs #-}
   221 
   221 
   222 module Isabelle.Library (
   222 module Isabelle.Library (
   223   (|>), (|->), (#>), (#->),
   223   (|>), (|->), (#>), (#->),
   224 
   224 
   225   fold, fold_rev, single, the_single, map_index, get_index, separate,
   225   fold, fold_rev, single, the_single, singletonM, map_index, get_index, separate,
   226 
   226 
   227   StringLike, STRING (..), TEXT (..), BYTES (..),
   227   StringLike, STRING (..), TEXT (..), BYTES (..),
   228   show_bytes, show_text,
   228   show_bytes, show_text,
   229 
   229 
   230   proper_string, enclose, quote, space_implode, commas, commas_quote, cat_lines,
   230   proper_string, enclose, quote, space_implode, commas, commas_quote, cat_lines,
   271 single x = [x]
   271 single x = [x]
   272 
   272 
   273 the_single :: [a] -> a
   273 the_single :: [a] -> a
   274 the_single [x] = x
   274 the_single [x] = x
   275 the_single _ = undefined
   275 the_single _ = undefined
       
   276 
       
   277 singletonM :: Monad m => ([a] -> m [b]) -> a -> m b
       
   278 singletonM f x = the_single <$> f [x]
   276 
   279 
   277 map_index :: ((Int, a) -> b) -> [a] -> [b]
   280 map_index :: ((Int, a) -> b) -> [a] -> [b]
   278 map_index f = map_aux 0
   281 map_index f = map_aux 0
   279   where
   282   where
   280     map_aux _ [] = []
   283     map_aux _ [] = []