Glad I could help! Note, though, that the compiler was giving you a pretty strong hint (zeroing in on 'substitute' vs 'substitution' as the difference between the expected and actual types), and in general is pretty good at giving useful error messages. It won't always figure out exactly what's wrong (I've had my share of "I am looking for one of the following things: end of input, whitespace"), but it does tend to give more useful error messages than a lot of other compilers (I'm looking at you, every C++ compiler ever).
On Tuesday, 19 July 2016 19:18:23 UTC+10, Andreas Kobler wrote: > > Thanks a lot! > Bad typo... was not really awake this morning :-/ Now it works as expected! > > 2016-07-19 10:58 GMT+02:00 Ian Mackenzie <[email protected] > <javascript:>>: > >> Try 'rule.substitution' instead of 'rule.substitute'. It looks like the >> compiler sees the 'rule.substitute' line and assumes that the 'rule' >> variable is something that has a 'substitute' field (and then gets confused >> when you try to pass such an object to the RuleTest constructor), instead >> of checking it first against your 'apply' type annotation that says that >> the second argument is of type Rule. >> >> On Tuesday, 19 July 2016 18:15:16 UTC+10, Andreas Kobler wrote: >>> >>> Thanks for your hint! The reason for the re-declaration is: Without that >>> line, the compiler yields the following error message. My re-declaration >>> line was not well-founded, I just try-n-error'ed it out. Is is a >>> record-thing, do I call the RuleTest constructor in a wrong way? Do you >>> have an explanation for that compiler error without the rule=rule line? Or >>> a pointer in a direction how I can figure it out? >>> >>> Many thanks >>> >>> Code chunk adapted to: >>> >>> apply : String -> Rule -> RuleTest >>> apply input rule = >>> let >>> output = replace rule.regex rule.substitute input >>> matched = input /= output >>> in >>> RuleTest rule input output True >>> >>> >>> ==== error in test.elm:55:5: ==== >>> The 1st argument to function `RuleTest` is causing a mismatch. >>> Function `RuleTest` is expecting the 1st argument to be: >>> { ..., substitution : ... } >>> But it is: >>> { a | ..., substitute : ... } >>> ---- >>> [Finished in 0.1s with exit code 1] >>> [Elm says]: To highlight build errors: Install with Package Control: >>> Highlight Build Errors >>> >>> >>> >>> Am Dienstag, 19. Juli 2016 09:07:11 UTC+2 schrieb Ian Mackenzie: >>>> >>>> The issue is likely with the rule = rule line, as Elm sees that as a >>>> recursive variable definition which has known bugs ( >>>> https://github.com/elm-lang/elm-compiler/issues/873). You should just >>>> be able to take that line out, there's no need to re-declare a variable >>>> with the same name as an argument. >>>> >>>> On Tuesday, 19 July 2016 16:59:04 UTC+10, Andreas Kobler wrote: >>>>> >>>>> Hi all >>>>> >>>>> Just started to play around with elm and very eager to get more fluid. >>>>> I picked a silly POC scenario of a rule composer: basically you have >>>>> regex >>>>> rules and want to edit/test them in a form. When applying a regex and >>>>> showing the replace output in an input field, I face an "undefined". >>>>> Below >>>>> you see the isolated part forcing my observation while applying the rule >>>>> directly in init. >>>>> >>>>> Unfortunately I could really not trace down to the root of this >>>>> happening. Is somebody able to tell me: >>>>> - What I am doing wrong? Why does there an "undefined" appear? (wenn >>>>> executing my own "replace" function in the REPL it works fine as expected) >>>>> - How do you guys debug such behaviour? >>>>> >>>>> Here my silly example: >>>>> >>>>> >>>>> module RuleTest exposing (..) >>>>> >>>>> >>>>> import Html.App >>>>> import Html exposing (..) >>>>> import Html.Attributes exposing (..) >>>>> import Regex >>>>> >>>>> >>>>> main : Platform.Program Basics.Never >>>>> main = >>>>> Html.App.program >>>>> { init = init >>>>> , view = viewRuleTest >>>>> , update = update >>>>> , subscriptions = \_ -> Sub.none >>>>> } >>>>> >>>>> >>>>> type alias Rule = >>>>> { regex : String >>>>> , substitution : String >>>>> } >>>>> >>>>> >>>>> type alias RuleTest = >>>>> { rule : Rule >>>>> , input : String >>>>> , output : String >>>>> , matched : Bool >>>>> } >>>>> >>>>> >>>>> type Msg >>>>> = StartTest String >>>>> >>>>> >>>>> >>>>> >>>>> -- init >>>>> init : (RuleTest, Cmd Msg) >>>>> init = >>>>> ( apply "reg1" (Rule "reg1" "sub1") >>>>> , Cmd.none >>>>> ) >>>>> >>>>> >>>>> -- update >>>>> update : Msg -> RuleTest -> (RuleTest, Cmd Msg) >>>>> update msg ruleTest = >>>>> case msg of >>>>> >>>>> >>>>> StartTest input -> >>>>> ( apply input ruleTest.rule, Cmd.none ) >>>>> >>>>> >>>>> >>>>> >>>>> apply : String -> Rule -> RuleTest >>>>> apply input rule = >>>>> let >>>>> output = replace rule.regex rule.substitute input >>>>> matched = input /= output >>>>> rule = rule >>>>> in >>>>> RuleTest rule input output True >>>>> >>>>> >>>>> replace : String -> String -> String -> String >>>>> replace regex substitute input = >>>>> Regex.replace Regex.All (Regex.regex regex) (\_ -> substitute) input >>>>> >>>>> >>>>> viewRuleTest : RuleTest -> Html Msg >>>>> viewRuleTest ruleTest = >>>>> div [] >>>>> [ label [] [ text "Pattern" ] >>>>> , input [ Html.Attributes.value ruleTest.rule.regex, disabled True >>>>> ] [] >>>>> , label [] [ text "Substitution" ] >>>>> , input [ Html.Attributes.value ruleTest.rule.substitution, >>>>> disabled True ] [] >>>>> , label [] [ text "Input" ] >>>>> , input [ Html.Attributes.value ruleTest.input, disabled True ] >>>>> [] >>>>> , label [] [ text "Output" ] >>>>> , input [ Html.Attributes.value ruleTest.output, disabled True ] >>>>> [] >>>>> , label [] [ text "matched" ] >>>>> , input [ type' "checkbox", checked ruleTest.matched ] [] >>>>> ] >>>>> >>>>> >>>>> Environment: >>>>> elm repl --version >>>>> 0.17.1 >>>>> OSX 10.11.3 >>>>> >>>>> { >>>>> "version": "1.0.0", >>>>> "summary": "helpful summary of your project, less than 80 >>>>> characters", >>>>> "repository": "https://github.com/user/project.git", >>>>> "license": "BSD3", >>>>> "source-directories": [ >>>>> "." >>>>> ], >>>>> "exposed-modules": [], >>>>> "dependencies": { >>>>> "elm-lang/core": "4.0.1 <= v < 5.0.0", >>>>> "elm-lang/html": "1.1.0 <= v < 2.0.0" >>>>> }, >>>>> "elm-version": "0.17.1 <= v < 0.18.0" >>>>> } >>>>> >>>>> >>>>> Thanks for any advice! >>>>> >>>>> Best, Andi >>>>> >>>>> >>>>> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "Elm Discuss" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/elm-discuss/-zSBcLpbWo0/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> [email protected] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
