Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple haskell string manage

Tags:

string

haskell

Theres is a little problem I want to solve with Haskell: let substitute a function that change all of the wildcards in a string for one concrete parameter. The function has de signature of:

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)"
like image 744
paurullan Avatar asked Jun 24 '26 22:06

paurullan


1 Answers

You could 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
like image 124
Dan Dyer Avatar answered Jun 27 '26 14:06

Dan Dyer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!