title: Expression was expected to have a type but here has type String
body: <p>It's my third time today running and this buzz word functional language F# is driving me mad yet when I get certain bits right it feels good </p>
  
  <p>earlier I had a problem with recursive loop someone suggested a way forward and now I am getting the above error, the problem is I know my type is going to be a string so why is the compiler complaining? </p>
  
  <p>Aim was to put 12 weeks of learning into practice so I wanted to work on basic chat bot so far I can hold a basic level conversation, however, there are few things that are still out of my scope for example </p>
  
  <p>why can't I call my type? IUserError to pass user input and check if they have said something that is not in my subject list then to response back with invalid input.</p>
  
  <p>My other issue is to keep things simple I want to convert all input into lowercase string this is also proven to be a challenge. </p>
  
  <p>and then there is numeric at some stage of the conversation user gets to room location for some reason I can find a way other than to do this check.</p>
  
  <p>there is very few tutorial online and the book I am using does not explain things well. I am pleased with what I have achieved so far </p>
  
  <p>if someone can explain where I am going wrong with this because in C# this would have been gone and dusted.:( </p>
  
  <p>here is my whole code feel free to discuss:</p>
  
  <pre><code>open System 
  open System.IO
  open System.Speech.Synthesis
  
  // required for regular expression
  open System.Text.RegularExpressions
    // init randomizer
    let rand = new Random()
    // recursive response function find the first match with a key token 
    // response back acordingly
  
    // Initialise a new instance of SpeechSynthesizer 
     let voice (sentence: string) =
  
     use speech = new SpeechSynthesizer(Rate= -3)
     //speech.SelectVoice("Microsoft Huihui Desktop")
  
     speech.Speak(sentence)
  
    // define functions  of set list  campus area 
    let mpCampusArea = Set.ofList ["Cisco Labs"; "The Bridge"; "Security 
    Area"; 
     "Mac Labs"; "Open Access"]
  
  
     //active patterns  
  
    //method for checking room number                                                                   
  
    let chkroom () = 
       let roomNumbers = seq {
        yield 158
        yield 123
        yield 333 }
  
     printfn "Room not found could it be :"
     for items in roomNumbers do
     printfn "%A" items
  
  
    let (|Campuses|None|) users =
    if Regex.Match(users,".*(MP?|mp|Curzon|curzon|ParkSide?).*" ).Success
    then Campuses
    else
      None 
  
    // Apply Active pattern 
    let(|Repair|None|) input = // any sentence with broken|break|damaged is 
    require repair
     if Regex.Match(input , ".*(broken?|break|damaged?).*").Success 
    then Repair
    else
       None  
  
   let (|ParkSide|None|) input =
   if Regex.Match(input , ".*(P158|P159|P160).*").Success
   then ParkSide 
   else
       None chkroom
  
  
   let (|RoomLocation|None|) str2 =
   if Regex.Match(str2, ".*(158|140|150).*").Success 
   then RoomLocation 
   else
      None chkroom
  
  
   // Define an active recognizer for keywords that express salutation.
  let (|Bye|Answer|NoSubject|MyGirlFriend|Faulty|None|) input =
  match input with
      | "goodbye" | "bye" | "go" |"get lost"
              -&gt; Bye
      | "who" | "how" | "when" |"where"
              -&gt; Answer
      | "car" |"what" |"name" |"bcu"
            -&gt; NoSubject
      | "lonely" |"love" | "friendship"
              -&gt; MyGirlFriend
      | "device" |"software" |"phone"
          -&gt;  Faulty
      | _     
              -&gt; None
  
   let (|Computer|Other|) input =
   match input with 
   |"goodbye"|"bye"|"go" -&gt; Computer
   |_ -&gt; Other
  
   // select possible likely hood response based on random number for hello 
   subject 
   // Interact with the user
   // Subject faulty software and Hardware
   let faulty_response (str:string) = 
     let x = rand.Next(5)
     match x with 
     | 0 -&gt; "My advice is to restart the software / hardware?" 
     | 1 -&gt; "My advice is relax it will be sorted."
     | 2 -&gt; "My advice is bin your device / software."
     | 3 -&gt; "Please throw your software / hardware in the recycle bin"
     | 5 -&gt; "Kiss your device / software as this always works for me."
     | _ -&gt; ""
  
  
     let  good_bye_response () =
     let b = rand.Next(5)
     match b with 
     | 0 -&gt; "Good bye Babe"
     | 1 -&gt; "Thank God " 
     | 2 -&gt; "We have to be positive love BCU"
     | 3 -&gt; "Live is beautiful but you are a smelly poo little fella BYE!"
     | 4 -&gt; "Good bye and thanks for complainting"
     | _ -&gt; ""
  
  
    let answer_response () =
        let x = rand.Next(10)
        match x with 
        | 0 -&gt; "Please go and complait to Waheed Rafiq"
        | 1 -&gt; "Please go and see Emmett Cooper"
        | 2 -&gt; "So you want me to kick a fuss?"
        | 3 -&gt; "What a waste of time"
        | 4 -&gt; "Please go and see BCU tech department"
        | 5 -&gt; "OMG and so what"
        | 6 -&gt; "Jump of the roof it will most likely help us all"
        | 7 -&gt; "Let's talk about the toliet shall we"
        | 8 -&gt; "why don't you use pattern matching with regular expressions!"
        | 9 -&gt; "Speak to the Queen she will  mostly likely deals with BCU 
         complaints"
        | _ -&gt; ""
  
     let  none_response (str:string) =
       let n = rand.Next(10) 
       match n with 
      | 0 -&gt; "What would  you"+ str + "like to chat about ?" 
      | 1 -&gt; "I do not understand please ask again !"
      | 2 -&gt; "How about you Speak english and I log your helpdesk call yeah?"
      | 3 -&gt; "Sorry to hear that. Are you sure you want to complaint ?"
      | 4 -&gt; "This is a complaint Chat bot where you log helpdesk calls. 
      Please Refer to Cortana for her services.!"
  
  
      | 5 -&gt; "Let just complaint yeah for the sake of complaining ?"
      | 6 -&gt; "OKay what is your complaint about ?"
      | 7 -&gt; "Are you a human because you certainly do not behave like one!"
      | 8 -&gt; "The moon is epic. What is broken ?"
      | 9 -&gt; "Do you always complaint? Try logging it like my PC is broken 
          yeah !"
      | _ -&gt; ""
  
  
    type Day =
       | Monday
    | Tuesday
    | Wednesday
    | Thursday
    | Friday
    | Saturday
    | Sunday
  
   let isWeekend x = 
       match x with 
       |Saturday |Sunday -&gt; true
       |_-&gt; false
  
  
  
   // using regular expression to tokenisse line of text 
   let matchWords = Regex(@"\w+")
  
   let token (text:string) =
       text.ToLowerInvariant()
       |&gt; matchWords.Matches
  
       // Crossing the stream  
     type IUserError =
        interface
      end
  
     type Error = { ErrorMessage:string; ErrorCode:int}
           interface IUserError
  
     type Success = { Status:string }
             interface IUserError
  
     let error  = {ErrorMessage = "Incorrect input please enter a subject 
     phase"; 
      ErrorCode = 250} :&gt; IUserError
  
     match error with 
     | :? Error as e -&gt; printfn "Code %i \n Message: %s" e.ErrorCode 
       e.ErrorMessage
     | :? Success -&gt; printfn "Success"
     |_ -&gt; failwith "Invalid option"
  
     //printfn "%A" error
  
     //recursive response function
    let rec response (token: string) (str: string) =
    match token with
     | Bye
         -&gt; good_bye_response ()
  
     | Answer
          -&gt; answer_response ()
     | Faulty
              -&gt; faulty_response  str
     | Repair
          -&gt; 
             sprintf "%s" "Which Campus is the device in?"
     | Campuses
          -&gt; sprintf "%s" "Which room is the device in?"
     | RoomLocation 
          -&gt;  sprintf "%s" "Your call is log. Do you wish to quit?"
     |_ when token.Contains("yes") -&gt;  "Okay logging you out"
     |_ when token.Contains("no") -&gt; answer_response () 
     | NoSubject 
              -&gt; none_response str
  
     | None when (str.IndexOf(" ") &gt; 0) 
          -&gt; response (str.Substring(0,str.IndexOf(" "))) 
      (str.Substring(str.IndexOf(" ")+1))
     | None when (str.IndexOf(" ") &lt; 0) 
          -&gt; response str ""
  
  
     let rec chat () =
     let valueInput = Console.ReadLine()
     printf "Helpdesk-BCU Response --&gt; %s \n" (response "" valueInput)
     let keepRunning, message = response valueInput 
     printfn "&gt;&gt; %s" message
     if keepRunning then chat()
  
  
  
  
    //let rec chat () =
    //    if Break = false then
    //    let valueInput = Console.ReadLine()
    //    printf "Helpdesk-BCU Response --&gt; %s \n" (response "" valueInput)
   //    if Break = false then 
     //      chat()
        //    else
        //      ChatEnd()
  
     let BCU_response (str: string) =
     if (str.IndexOf(" ") &gt; 0) then
     response (str.Substring(0,str.IndexOf(" "))) (str.Substring(str.IndexOf(" 
      ")+1)) + "\n"
    else
    response str "" + "\n"
  
  // call back feature for the chatbot 
  
  
  //[&lt;EntryPoint&gt;]
     //let main argv = printfn "%A" argv
  
  
   // Advance expression lamba [ Emmett helps required] 
  
   let ifancyHerList =
    [
      ("Sara",1); ("Saima",2); ("Zoe",3); ("Scarlett",4);
      ("Jennifer",5);("Sandra Bullock",6)
    ]
  
   let myGirlFriend () =
   List.pick (fun funToNight  -&gt;
      let n = rand.Next(10)
      if   (snd funToNight) = n
      then Some (fst funToNight)
      else None
    ) ifancyHerList
  
    //match myGirlFriend with
    //| Some name -&gt; printfn "Your date for tonight is %A lucky fella" name
    //| None      -&gt; printfn "You don't have a date tonight!"
   //
  
    printfn "Welcome to the BCU Complaint Chat Bot"
    printf "Please enter your first name --&gt;"
    let data = Console.ReadLine()
  
   //let rec complaints n =
   //    printf "%s what do you want to complain about? --&gt;" data
  
  
  
   //complaints()
   chat()
  
   printfn "The avaialbe areas at Millennium point are: %A" mpCampusArea
   printfn "Which day is Weekend on?"
   let x = Console.ReadLine()
  
  
  
   0
  </code></pre>
  
  <p>any helps / pointers / anything as this is driving me nuts </p>
  
  <p>I shall post a link direct to the project file if you wish to download it and have a closer look , much appericate your support. </p>
  
  <p>the link to the <a href="https://1drv.ms/f/s!AtdKsCaxzbVuxoEVIrCy5C7d4ElYkQ" rel="nofollow noreferrer">project file</a> </p>