Im new to Gatling tool, trying to pass multiple header value from another file but im facing error while compiling.
Code:
val header0 = List(Map(
"Ocp-Apim-Subscription-Key" -> TestParameters.Keyvalue,
"UserId" -> TestParameters.UserID
))
Error:
ingInformation.scala:22:13: type mismatch;
found : scala.collection.immutable.Map[String,java.io.Serializable]
required: Map[String,String]
.headers(header0)
^
Why do you make header0 a List[Map[String, String]]?
It should be a Map[String, String]:
val header0 = Map(
"Ocp-Apim-Subscription-Key" -> TestParameters.Keyvalue,
"UserId" -> TestParameters.UserID
)
Also, as explained in the documentation, header values must be Strings. So if TestParameters.Keyvalue or TestParameters.UserID are anything else, such as numbers, you must convert them, eg with toString.
Related
Right now, when I have a Result type, it seems like I need to do a match to find if it is ok, or not.
So, I am trying to simplify this to be able to use if, like that:
let a : Result<string, string> = ...
if a.IsOk then ....
Here is my attempt
[<AutoOpen>]
module ResultHelper =
type Result with
member this.IsOk =
match this with
| Ok _ -> true
| Error _ -> false
but this will not compile.
Using:
type Result<_, _> with
doesn't help either
How can I achieve this?
The correct syntax is to give the type parameters names. As a bonus, this will allow you to refer to them in the code if you need to.
type Result<'a, 'b> with
member this.IsOk =
match this with
| Ok _ -> true
| Error _ -> false
P.S. For the future, please note that "will not compile" is not a good description of a problem. Please make sure to always include the full error message.
I am reading XML File in FAKE script using XMLHelper.XMLRead but it is throwing an error i.e.
The type '(string -> string ->seq<string>)' is not a type whose value can be enumerated with this syantax , i.e. is not compatible with either seq<_>,IEnumerable<_> or IEnumerable and does not have a GetEnumerator method
Below Is my code :
let x = XMLHelper.XMLRead true "D:/test/Version.Config" "/version/major/minor"
Target "New" (fun _ ->
for i in x do
printf "%s" i
)
If you look at the API documentation for XMLHelper, you'll see that the function signature for XMLRead looks like this:
failOnError:bool -> xmlFileName:string -> nameSpace:string -> prefix:string -> xPath:string -> seq<string>
It looks like you're specifying the failOnError, xmlFileName and nameSpace parameters*, but you didn't specify the last two string parameters. Since F# uses partial application, that means that what you're getting back from your XMLRead invocation is a function that is waiting for two more string parameters (hence the string -> string -> (result) function signature in the error message you got).
* You probably intended for "/version/major/minor" to fill the xPath parameter, but F# applies parameters in the order given, so it filled the third parameter, which was nameSpace.
To fix this, specify all the parameters that XMLRead expects. I've looked at the XMLRead source, and the nameSpace and prefix parameters should be empty strings if you're not using XML namespaces in your input document. So what you want is:
let x = XMLHelper.XMLRead true "D:/test/Version.Config" "" "" "/version/major/minor"
Target "New" (fun _ ->
for i in x do
printf "%s" i
)
BTW, now that I've looked at your other question, I think you'll want the XMLHelper.XMLRead_Int function:
let minorVersion =
match XMLHelper.XMLRead_Int true "D:/test/Version.Config" "" "" "/version/major/minor" with
| true, v -> v
| false, _ -> failwith "Minor version should have been an int"
Once your code gets past that line, either you have an int in minorVersion, or your build script has thrown an error and exited so that you can fix your Version.Config file.
I feel like a total noob for having to ask this but it's got me stumped.
I set a format string like this:
let fs = "This is my format test %s"
Then I attempt to use it like so:
let s = sprintf fs "testing"
When I do so I get this error:
//stdin(26,17): error FS0001: The type 'string' is not compatible with the type 'Printf.StringFormat<('a -> 'b)>'
So I then tried this:
let s = sprintf (Printf.StringFormat fs) "test"
to which the REPL responded:
//stdin(28,18): error FS1124: Multiple types exist called 'StringFormat', taking different numbers of generic parameters. Provide a type instantiation to disambiguate the type resolution, e.g. 'StringFormat<_>'.
So I then tried this:
let s = sprintf (Printf.StringFormat<string> fs) "test"
And I get this:
//stdin(29,18): error FS0001: The type ''a -> 'b' does not match the type 'string'
Am I missing something painfully obvious? This is using F# 3.0 on the Mac from the Xamarin Studio F# Interactive Window.
So you actually need to create a StringFormat which has a function type as follows
> sprintf (Printf.StringFormat<string->string>("Hello %s")) "World";;
val it : string = "Hello World"
In Section 6.3.16 of the spec, an example of this is shown.
Here is my code: http://pastie.org/private/t37ectjdnplit66zidj6hq
This code is for a pascal-like language parser. I have a problem in these lines : 178 , 181, 193. When I have a defined grammar with the keyword : [Any], I run it successfully ! but when I replace that keyword by one of traits and "case classes" , it notifies me have a mistake ! I think I don't understand the meanings when use the code : parser[???]. Can anybody help me to resolve these problems?
line 181: def val_type : Parser[Type] = primitive| array_type | string_type
line 193: def ident_list : Parser[List[Id]] = ident ~(rep(","~> ident))
Updated:
Here are the corresponding errors:
line 181: type mismatch; found : MPRecognizer.this.Parser[Any] required: MPRecognizer.this.Parser[Type]
line 193: type mismatch; found : MPRecognizer.this.Parser[MPRecognizer.this.~[String,List[String]]] required: MPRecognizer.this.Parser[Id]
You need to show us the original code, not the one you modified by making everything return Parser[Any].
The error messages tell you that not all alternatives produce an instance of Type. For example, check that the methods primitive, array_type and string_type all return a Parser[Type]. Add the type annotation to each of them, and if you get type errors in the modified definitions, narrow it down further in the same way.
Although it seems lie a simple issue, I am unable to write to a configuration file from an F# console application. My last attempt looks like
let config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal)
// config.AppSettings.SectionInformation.AllowExeDefinition <-ConfigurationAllowExeDefinition.MachineToLocalUser
match self.FileName with
| Some name -> config.AppSettings.Settings.["FileName"].Value <- name
| None -> ()
config.Save(ConfigurationSaveMode.Modified)
I got all sorts of errors. The one corresponding to this code is
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Configuration.ConfigurationElement.SetPropertyValue(ConfigurationProperty prop, Object value, Boolean ignoreLocks) ...
There is no good documentation in F# and I find it hard to follow C#/VB documentation.
Any suggestions?
You have to check for null and either update or add accordingly.
Something like this:
let config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal)
let settings = config.AppSettings.Settings
let set (s:KeyValueConfigurationCollection) key value =
match s.[key] with
| null -> s.Add(key,value)
| x -> x.Value <- value
match self.FileName with
| Some name -> set settings "Filename" name
| _ -> ()