The likely purpose of Mark Twain's use of dialect is because he wanted it to be true to the setting of his novel and the characters. Huck Finn isn't a very educated individual, for example, so it accurately represents his character to include grammar errors and such. The reasoning for other character's dialects is similar. Jim's dialect is also representational of how most in his position (a slave) would have spoken at the time.