Theres a little problem I want to solve with Haskell: replace a function that changes all characters in a string for one specific parameter. The function has a de-signature:
subs :: String -> String -> String -> String -- example: -- subs 'x' "x^3 + x + sin(x)" "6.2" will generate -- "6.2^3 + 6.2 + sin(6.2)"
You can use the Text.Regex package .
Your example might look something like this:
import Text.Regex(mkRegex, subRegex) subs :: String -> String -> String -> String subs wildcard input value = subRegex (mkRegex wildcard) input value
For such cases, you can use the text-format-simple library :
import Text.Format format "{0}^3 + {0} + sin({0})" ["6.2"]
. http://bluebones.net/2007/01/replace-in-haskell/ , , .
(Text.Regex.Posix) search-replace /\Wx\W/ ( Perl). x 6.2 x + quux.
Text.Regex.Posix
/\Wx\W/
x
6.2
x + quux
Haskell Regex Replace for more information (I think this should be imported into SO.
For an extra hard core, you can parse your expression as an AST and perform a replacement at that level.
Source: https://habr.com/ru/post/1696884/More articles:Encryption / Decryption on machines - this is no-no - windows-vistaDoes emacs have something like vi "set number"? - editorHow can I execute an action n-many times in TextMate (both Emacs and Vim can do this easily!)? - textmateHow to programmatically sanitize cfquery ColdFusion settings? - coldfusionGuile Outline - Cited Period? - schemeHow to tweak in jsp? - jspПочему моя программа cocoa получает EXC_BAD_ACCESS во время запуска? - cocoaBest PHP thumbnailer / resizer class? - phpRetrieving data from an oracle database as a CSV file (or any other custom text format) - databaseHow do you classify text based content? - algorithmAll Articles