Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8861855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:35:11+00:00 2026-06-14T15:35:11+00:00

I am student and in my programming course we have to learn Haskell. So

  • 0

I am student and in my programming course we have to learn Haskell. So I am new to it and i don’t have that much experience. Also I am not familiar with posting questions in a forum.

So first of all I will post the library, I have to work with.
(DA : Deterministic Automaton)

type State = Integer
type DA = (State, State -> Char -> State, State -> Bool)
type ListDA = (State, [((State, Char), State)], [State])

a :: DA
a = (0, delta, (==1))
  where
    delta 0 'a' = 1
    delta 1 'a' = 1
    delta 2 'a' = 1
    delta 0 'b' = 2
    delta 1 'b' = 2
    delta 2 'b' = 2

toDA :: ListDA -> DA
toDA (start, delta, final) = (start, deltaFun delta, (`elem` final))
  where deltaFun dl = curry (fromMaybe 0 . flip lookup dl)  

The toDA function takes an automaton in its list representation and converts it into an automaton. This function and the rest of the library is given by the chair of the lecture.

The problem is now to write a function of type

advance :: DA -> State -> String -> State

This function takes an automaton, a state and a String and returns the state of the automaton after reading the String.

The Idea is clear so far. An automaton of type DA has got a state-transition-function delta. So the function “advance” has to call that delta function in some way. But how can I access a function, that is integrated in a type?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:35:12+00:00Added an answer on June 14, 2026 at 3:35 pm

    You use pattern matching for that:

    advance :: DA -> State -> String -> State
    advance (start, step, accept) fromState chars = ....
    

    The type keyword just introduces type synonyms. DA is just a synonym for a triple (Integer, Integer -> Char -> Integer, Integer -> Bool).

    Your naming is confusing. delta in the definition of a automaton is a state transition function, but in the definition of toDA function, a parameter named delta is a list. ListDA type is also just a synonym for a triple (a different one – of a state, a list of transitions, and a list of acceptable states).

    Here is how this can be coded, using recursion for loops:

    advance (_, step, _) fromState chars = go fromState chars
      where
        go s []     = ...  -- stop, and produce the state as the answer,
                           -- when the input string (list of chars) has ended
        go s (c:cs) =         -- if not, then
          let s2 = step s c   -- make one step
          in  go .......      -- and loop with new values
    

    Notice we have no need here for the start or accept variables, so we can use the anonymous variable pattern _ there. Also, step is a function of type State -> Char -> State, and that dictates the order of arguments used in the function call there. I.e. it accepts a state and a character, and produces a new state.

    If you don’t know Haskell at all, you will likely benefit from reading (and working through) a good tutorial, like this one.

    Lastly, since you’ve said you’re “not familiar with posting questions in a forum”, please read about accepting answers, and FAQ in general.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java programming lab-exercise in a course with students that I'd like
I'm a undergrad Student at a German University. I have a team Programming Course
I am a college student taking a intro to programming C#. That being said,
I am college student (computer science) and have just started a C# programming class.
I am a student and new to programming. It might be a simple error,
I'm a programming student in my 2nd OOP course, which is taught in C++.
I have a number of student with java programming assigment written using (most probabaly)
I am doing a homework for my Systems Programming course. I have to implement
I am a student in a concepts of programming class. The lab is run
I'm a student in my first C++ programming class, and I'm working on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.