Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Control.Applicative
  2.  
  3. data C = C
  4. data T = T
  5. data P = P
  6. data N = N deriving Eq
  7. data S = S
  8. data S' = S'
  9.  
  10. getParameterValuestoSeq :: C -> [T]
  11. getParameterValuestoSeq = undefined
  12.  
  13. getParameter :: T -> P
  14. getParameter = undefined
  15.  
  16. getVariableName :: P -> N
  17. getVariableName = undefined
  18.  
  19. getValue :: T -> S'
  20. getValue = undefined
  21.  
  22. option :: S' -> Maybe S
  23. option = undefined
  24.  
  25. getDefaultValue :: P -> S
  26. getDefaultValue = undefined
  27.  
  28. headOption :: [x] -> Maybe x
  29. headOption = undefined -- listToMaybe
  30.  
  31. getOrElse :: x -> Maybe x -> x
  32. getOrElse = undefined -- fromMaybe
  33.  
  34. f :: C -> N -> Maybe S
  35. f scenario name = headOption . fmap (\t -> getDefaultValue (getParameter t) `getOrElse` option (getValue t)) $ filter (\t -> getVariableName (getParameter t) == name) (getParameterValuestoSeq scenario)
  36.  
  37. f' :: C -> N -> Maybe S
  38. f' scenario name =
  39.   let z = headOption $ filter (\t -> getVariableName (getParameter t) == name) (getParameterValuestoSeq scenario)
  40.   in fmap ((getOrElse . getDefaultValue . getParameter) <*> (option . getValue)) z
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement