<commit_before>---
title: Migrate from PureScript/Haskell
parent: Recipes
nav_order: 8
---

# Migrate from PureScript/Haskell

This guide shows you how to use `fp-ts` concepts if you have prior experience with [PureScript](http://www.purescript.org/) or [Haskell](https://www.haskell.org/).
{: .fs-6 .fw-300 }

---

## Do notation

PureScript

```purescript
do
  print "foo"
  print "bar"
  x <- readLine
  print x
```

TypeScript

```ts
import { pipe } from 'fp-ts/lib/pipeable'
import * as T from 'fp-ts/lib/Task'

declare function print(s: string): T.Task<void>
declare const readLine: T.Task<string>

pipe(
  print('foo'),
  T.chain(_ => print('bar')),
  T.chain(_ => readLine),
  T.chain(print)
)
```

## Data

PureScript

```purescript
--   ↓-- type
data Foo = Bar String | Baz Boolean
--         ↑------------↑-- constructors
```

TypeScript

```ts
interface Bar { type: 'Bar'; value: string }
interface Baz { type: 'Baz'; value: boolean }
// type
type Foo = Bar | Baz
// constructors
const Bar = (value: string): Foo => ({ type: 'Bar', value })
const Baz = (value: boolean): Foo => ({ type: 'Baz', value })
```

## Polymorphic data

PureScript

```purescript
data Option a = None | Some a
```

TypeScript

```ts
declare module 'fp-ts/lib/HKT' {
  interface URItoKind<A> {
    Option: Option<A>
  }
}

export const URI = 'Option'

export type URI = typeof URI

export type Option<A> = None | Some<A>

export interface None {
  readonly _tag: 'None'
}

export interface Some<A> {
  readonly _tag: 'Some'
  readonly value: A
}

export const none: Option<never> = { _tag: 'None' }

export const some = <A>(a: A): Option<A> => new Some(a)
```

## Pattern matching
<commit_msg>Bad syntax and non-existent class<commit_after>---
title: Migrate from PureScript/Haskell
parent: Recipes
nav_order: 8
---

# Migrate from PureScript/Haskell

This guide shows you how to use `fp-ts` concepts if you have prior experience with [PureScript](http://www.purescript.org/) or [Haskell](https://www.haskell.org/).
{: .fs-6 .fw-300 }

---

## Do notation

PureScript

```purescript
do
  print "foo"
  print "bar"
  x <- readLine
  print x
```

TypeScript

```ts
import { pipe } from 'fp-ts/lib/pipeable'
import * as T from 'fp-ts/lib/Task'

declare function print(s: string): T.Task<void>
declare const readLine: T.Task<string>

pipe(
  print('foo'),
  T.chain(_ => print('bar')),
  T.chain(_ => readLine),
  T.chain(print)
)
```

## Data

PureScript

```purescript
--   ↓-- type
data Foo = Bar String | Baz Boolean
--         ↑------------↑-- constructors
```

TypeScript

```ts
interface Bar { type: 'Bar'; value: string }
interface Baz { type: 'Baz'; value: boolean }
// type
type Foo = Bar | Baz
// constructors
const Bar = (value: string): Foo => ({ type: 'Bar', value })
const Baz = (value: boolean): Foo => ({ type: 'Baz', value })
```

## Polymorphic data

PureScript

```purescript
data Option a = None | Some a
```

TypeScript

```ts
declare module 'fp-ts/lib/HKT' {
  interface URItoKind<A> {
    Option: Option<A>
  }
}

export const URI = 'Option'

export type URI = typeof URI

export type Option<A> = None | Some<A>

export interface None {
  readonly _tag: 'None'
}

export interface Some<A> {
  readonly _tag: 'Some'
  readonly value: A
}

export const none: Option<never> = ({ _tag: 'None' })

export const some = <A>(a: A): Option<A> => ({ _tag: 'Some', value: a })
```

## Pattern matching

{'fraction_non_alphanumeric': 0.17073888725345893, 'fraction_numerical': 0.0029437739181630853, 'mean_word_length': 3.412987012987013, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 33, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1175938', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1212, 'n_words': 376}